flux.brokermod module
- class flux.brokermod.BrokerLogger(h)
Bases:
objectLogger bridge from a broker module to the Flux ring buffer.
Provides convenience methods (
debug,info,notice,warning,error,critical,alert,emerg). Also callable aslog(level, msg)so it can serve as a drop-in wrapper forhandle.log().The
levelattribute is a threshold: messages with a numerically higher syslog priority value (i.e. lower urgency, such asLOG_DEBUG) are silently dropped when they exceed the threshold. The defaultsyslog.LOG_DEBUGpasses all messages through, matching C module behaviour where the broker's global log level is the only filter.levelmay be assigned a syslog integer constant or a level-name string (e.g."info","debug"); readinglevelalways returns the integer.- LEVEL_NAMES = {'alert': 1, 'crit': 2, 'debug': 7, 'emerg': 0, 'err': 3, 'info': 6, 'notice': 5, 'warning': 4}
- alert(msg: str) None
- critical(msg: str) None
- debug(msg: str) None
- emerg(msg: str) None
- error(msg: str) None
- info(msg: str) None
- property level
Current log-level threshold as a syslog integer constant.
- property level_name
Current log level as a name string (e.g.
'info').
- notice(msg: str) None
- warning(msg: str) None
- class flux.brokermod.BrokerModule(h, *args)
Bases:
objectBase class for Python broker modules.
Subclass this and use the
request_handler()andevent_handler()decorators to register message handlers, then callrun()to start the reactor. Handler topics are automatically prefixed with the module name unlessprefix=Falseis passed to the decorator.Example:
from flux.brokermod import BrokerModule, event_handler, request_handler class MyModule(BrokerModule): @request_handler("info") def info(self, msg): self.handle.respond(msg, self.name) @event_handler("panic") def panic(self, msg): self.stop_error()
When this is the only
BrokerModulesubclass in the file and nomod_main()is defined, the loader synthesizes the entry point automatically. An explicitmod_main()is only needed to resolve ambiguity when multiple subclasses are present.- property args
Tuple of module arguments passed at load time.
- debug_test(flag, clear=False)
Test a module debug bit, optionally clearing it.
Returns True if the bit identified by flag is set. If clear is True the bit is atomically cleared after being read. Bits are set externally via
flux module debug --setbit N <module-name>.
- property name
The module name as assigned by the broker.
- run()
Run the reactor until stopped.
Raises
OSErrorif the reactor was stopped with an error (e.g. viastop_error()) or if a Python exception was set on the handle during a callback.
- set_running()
Signal to the broker that the module is now running.
Call this before performing synchronous initialization in
run()to allowflux module loadto return instead of waiting for the reactor to start. See flux_module_set_running(3).
- flux.brokermod.event_handler(topic, prefix=True)
Decorator to register a method as an event handler.
The handler is invoked with (self, msg) when an event matching
<module_name>.<topic>is received. Ifprefix=False, the topic is used as-is without prepending the module name.
- flux.brokermod.request_handler(topic, prefix=True, allow_guest=False)
Decorator to register a method as a request handler.
The handler is invoked with (self, msg) when a request matching
<module_name>.<topic>is received. Ifprefix=False, the topic is used as-is without prepending the module name. Ifallow_guest=True, requests from non-owner users (FLUX_ROLE_USER) are also accepted.
- flux.brokermod.resolve_entry_point(mod)
Resolve the entry point callable from a Python broker module object.
If the module defines
mod_main()it is returned as-is. Otherwise, a singleBrokerModulesubclass is searched for in the module's namespace and its entry point synthesized ascls(h, *args).run().- Raises
ValueError -- if no entry point can be determined, or if multiple
BrokerModulesubclasses are found without an explicitmod_main().