Event Modules

Event modules are building blocks which perform 1 clearly defined action to the events passing through them.

Event modules are functionally isolated blocks of code which do not directly invoke each other’s functionality. They only interact by passing wishbone.event.Event instances to each other’s wishbone.Queue queues from where the incoming events are consumed and processed by a function registered by wishbone.Actor.registerConsumer().

Event modules run as Gevent greenlets in the background and are created by inheriting wishbone.Actor as a baseclass and live inside a wishbone.router.Default instance.

Modules typically have, but are not limited to an inbox, outbox, success and failed queue.

A queue can only be connected to 1 single queue.

Note

If you need to have “one to many” or “many to one” connections then you can use the wishbone.module.Fanout and wishbone.module.Fanout modules.

The wishbone.Actor baseclass must be initialized by passing a wishbone.actor.ActorConfig instance which controls the behavior of the module instance.

class wishbone.Actor(config)[source]
connect(source, destination_module, destination_queue)[source]

Connects the <source> queue to the <destination> queue. In fact, the source queue overwrites the destination queue.

getChildren(queue=None)[source]

Returns the queue name <queue> is connected to.

loop()[source]

The global lock for this module

metricProducer()[source]

A greenthread which collects the queue metrics at the defined interval.

registerConsumer(function, queue)[source]

Registers <function> to process all events in <queue>

Do not trap errors. When <function> fails then the event will be submitted to the “failed” queue, If <function> succeeds to the success queue.

sendToBackground(function, *args, **kwargs)[source]

Executes a function and sends it to the background.

Background tasks are usually running indefinately. When such a background task generates an error, it is automatically restarted and an error is logged.

start()[source]

Starts the module.

stop()[source]

Stops the loop lock and waits until all registered consumers have exit otherwise kills them.

submit(event, queue)[source]

A convenience function which submits <event> to <queue>.

Warning

When a queue is not connected any message submitted to it will be dropped. This is by design to ensure queues do not fill up without ever being consumed.

Logs

Each event module has a wishbone.Logging instance called self.logging which can be used to generate logs. The user is responsible for connecting the necessary modules to collect and process the log events from each of the modules’ logs queue.

Log({'message': 'Received stop. Initiating shutdown.', 'module': 'metrics_graphite', 'pid': 18179, 'level': 6, 'time': 1454272074.556823})
class wishbone.event.Log(time, level, pid, module, message)[source]

A Wishbone log object

Note

If you are bootstrapping a server from CLI then the logs queue of each module will be connected to stdout or syslog depending on the startup mode.

Warning

If no module is consuming the logs from the module’s logs queue, adding new logs events to the full queue will cause the event to be dropped.

Metrics

Each Wishbone module collects statistics of its queues. These metric events are submitted to the modules’ metrics queue. The user is responsible for connecting the necessary modules to collect and process the metric events from each of the modules’ metrics queue.

Metrics are generated at the interval determined by the wishbone.actor.ActorConfig instance passed to the module.

class wishbone.event.Metric(time, type, source, name, value, unit, tags)[source]

A Wishbone metric object

Metric({'tags': (), 'unit': '', 'value': 0, 'name': 'module.input.queue.failed.size', 'source': 'server01', 'type': 'wishbone', 'time': 1454271176.479039})