Module | Ruote::LocalParticipant |
In: |
lib/ruote/part/local_participant.rb
|
Provides methods for ‘local’ participants.
Assumes the class that includes this module has a context method that points to the worker or engine ruote context.
It‘s "local" because it has access to the ruote storage.
context | [RW] | The engine context, it‘s a local participant so it knows about the context in which the engine operates… |
error | [RW] | Set right before a call to on_error |
fei | [W] | Usually set right before a call to on_cancel or cancel |
flavour | [RW] | Usually set right before a call to on_cancel or cancel |
msg | [RW] | Set right before a call to on_error |
workitem | [W] | Usually set right before a call to on_workitem or accept? |
Test shortcut, alleviates the need to set the workitem before calling dont_thread?, do_not_thread? or do_not_thread.
Test shortcut, alleviates the need to set fei and flavour before calling cancel / on_consume.
Test shortcut, alleviates the need to set the workitem before calling consume / on_workitem.
Returns the Ruote::ParticipantExpression that corresponds with this participant.
If a wi_or_fei arg is given, will return the corresponding flow expression. This arg is mostly here for backward compatibility.
Up until ruote 2.3.0, the participant name had to be fetched from the workitem. This is a shortcut, it lets you write participant code that look like
def on_workitem (workitem.fields['supervisors'] || []) << participant_name reply end
Use this method to re_dispatch the workitem.
It takes two options :in and :at for "later re_dispatch".
Look at the unschedule_re_dispatch method for an example of participant implementation that uses re_dispatch.
Without one of those options, the method is a "reject".
Participant implementations call this method when their on_workitem (consume) methods are done and they want to hand back the workitem to the engine so that the flow can resume.
the (wi=workitem) is mostly for backward compatibility (or for passing a totally different workitem to the engine).
Cancels the scheduled re_dispatch, if any.
An example of ‘retrying participant’ :
class RetryParticipant include Ruote::LocalParticipant def initialize(opts) @opts = opts end def on_workitem begin do_the_job reply rescue re_dispatch(:in => @opts['delay'] || '1s') end end def cancel unschedule_re_dispatch end end
Note how unschedule_re_dispatch is used in the cancel method. Warning, this example could loop forever…
Receivers and local participants share the stash_put and stash_get methods. The local participant has put and get which don‘t need an initial fei, thus get and put deal with the participant expression directly, whereas stash_put and stash_get can point at any expression.
‘put’ can be called as
put('secret' => 'message', 'to' => 'embassy') # or put('secret', 'message')