Input¶
Note
Input modules either take events from the outside world or generate events.
Input module properties:
- They have a protocol decoder method mapped to
wishbone.module.InputModule.decode()
in order to convert the incoming data into a workable datastructure. wishbone.actorconfig.ActorConfig.protocol_function
determines whetherwishbone.module.InputModule.generateEvent()
either expects events from the outside world to be Wishbone events or regular data.- Contextual data about the incoming event can/should be stored under
tmp.<module name>
. - Should always have an
destination
andnative_events
parameter. - Should use
wishbone.actor.Actor.generateEvent()
to generate the event in which to store the incoming data. It takes care of how the event is created in relation to the obligatorydestination
andnative_events
parameters. - If you’re setting a default decoder function make sure you use
wishbone.module.InputModule.setDecoder()
as this method will prevent overwrite any user defined decoder set viawishbone.actorconfig.ActorConfig
.
The builtin Wishbone Input modules:
Name | Description |
---|---|
wishbone.module.input.cron |
Generates an event at the defined time. |
wishbone.module.input.generator |
Generates an event at the chosen interval. |
wishbone.module.input.inotify |
Monitors one or more paths for inotify events. |
Input
modules must base wishbone.module.InputModule
:
-
class
wishbone.module.
InputModule
(config)[source]¶ Bases:
wishbone.actor.Actor
-
generateEvent
(data={}, destination=None)¶ Generates a new event.
This function can get overridden by
wishbone.module.InputModule._generateNativeEvent
.The provided
data
will be traversed in search of valid templates which then will be rendered.Parameters: Returns: An event containing
data
as a payload.Return type:
-
getDecoder
()[source]¶ Returns a new instance of the
handler()
method of the decoder set byself.setDecoder()
. Each concurrent incoming data stream should use its own instance of the decoder otherwise they end up overwriting each other’s content.
-
loop
()¶ The global lock for this module.
Returns: True when module is in running mode. False if not. Return type: bool
-
postHook
()¶ Is executed when module exits.
-
preHook
()¶ Is executed when module starts. Can be overriden by the user.
-
registerConsumer
(function, queue)¶ Registers <function> to process all events in <queue>
Don’t not trap errors here. When <function> fails then the event will be submitted to the “failed” queue, If <function> succeeds to the success queue.
Registering
function
to consumequeue
will also apply all the registered module functions against the events consumed from it.Parameters: Returns: None
-
renderEventKwargs
(event, queue=None)¶ Renders kwargs using the content of
event
and stores the result underevent.kwargs
.Parameters: Returns: The provided event instance.
Return type: wishbone.event.Event
-
renderKwargs
()¶ Renders kwargs without making use of event content. This is typically used when initiliazing a module and render the defined kwargs which do not need a event data for rendering.
Returns: None
-
sendToBackground
(function, *args, **kwargs)¶ Executes a function and sends it to the background. Such a function should never exit until
self.loop
returnsFalse
. This method wrapsfunction
again in a loop as longself.loop
returnsFalse
so thatfunction
is restarted and an error is logged.Parameters:
-
setDecoder
(name, *args, **kwargs)[source]¶ Sets the decoder with name <name> unless there’s already a decoder defined via
actorconfig.ActorConfig
.Parameters:
-
start
()¶ Starts the module.
Returns: None
-
stop
()¶ Makes
self.loop
returnFalse
and handles shutdown of of the registered background jobs.
-