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.

Methods

Included Modules

ReceiverMixin

Attributes

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?

Public Instance methods

Test shortcut, alleviates the need to set the workitem before calling accept?

_cancel(fei, flavour)

Alias for _on_cancel

_consume(wi)

Alias for _on_workitem

_do_not_thread(wi)

Alias for _dont_thread?

_do_not_thread?(wi)

Alias for _dont_thread?

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 on_reply.

Test shortcut, alleviates the need to set the workitem before calling consume / on_workitem.

Test shortcut, alleviates the need to set the workitem before calling rtimeout.

Returns the workitem as was applied when the Ruote::ParticipantExpression was reached.

If the _fei arg is specified, it will return the corresponding applied workitem. This args is mostly here for backward compatibility.

Returns the current fei (Ruote::FlowExpressionId).

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.

is_canceled?()

Alias for is_cancelled?

Returns true if the underlying participant expression is gone or cancelling.

Returns true if the underlying participant expression is ‘gone’ (probably cancelled somehow).

A shortcut for

  fexp.lookup_variable(key)

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".

reject(wi=nil, opts=nil)

Alias for re_dispatch

reply(wi=workitem)

Alias for reply_to_engine

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…

Returns the current workitem if no fei is given. If a fei is given, it will return the applied workitem for that fei (if any).

The optional fei is mostly here for backward compatibility (with 2.2.0)

Protected Instance methods

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')

[Validate]