Class Ruote::Exp::FlowExpression
In: lib/ruote/exp/ro_on_x.rb
lib/ruote/exp/flow_expression.rb
lib/ruote/exp/ro_persist.rb
lib/ruote/exp/ro_attributes.rb
lib/ruote/exp/ro_variables.rb
lib/ruote/exp/ro_filters.rb
lib/ruote/exp/ro_timers.rb
Parent: Object

‘re-opening’ the FlowExpression class to add timers related methods.

Methods

Included Modules

Ruote::WithH Ruote::WithMeta

Classes and Modules

Class Ruote::Exp::FlowExpression::HandlerEntry

Constants

COMMON_ATT_KEYS = %w[ if unless forget lose flank timeout timers on_error on_cancel on_timeout ]
VV = %w[ val value ]   Val and Value (Sense and Sensibility ?)
VAR_PREFIX_REGEX = /^(\/{0,2})\/*(.+)$/
PREFIX_REGEX = /^([^:]+):(.+)$/
F_PREFIX_REGEX = /^f/

Attributes

context  [R] 
error  [RW]  Mostly used when the expression is returned via Ruote::Engine#ps(wfid) or Ruote::Engine#processes(). If an error occurred for this flow expression, ps will set this error field so that it yields the ProcessError.

So, for short, usually, this attribute yields nil.

h  [R] 

Public Class methods

Called by the worker when it has something to do for a FlowExpression.

Returns a dummy expression. Only used by the error_handler service.

Fetches an expression from the storage and readies it for service.

Instantiates expression back from hash.

Keeping track of names and aliases for the expression

Public Instance methods

Returns true if the given fei points to an expression in the parent chain of this expression.

Returns a one-off Ruote::Workitem instance (the applied workitem).

Returns the value for attribute ‘key’, this value should be present in the array list ‘values’. If not, the default value is returned. By default, the default value is the first element of ‘values’.

Equivalent to attribute_text, but will return nil if there is no attribute whose values is nil.

Given something like

  sequence do
    participant 'alpha'
  end

in the context of the participant expression

  attribute_text()

will yield ‘alpha’.

Note : an empty text returns ’’, not the nil value.

Returns the attributes of this expression (like { ‘ref’ => ‘toto’ } or { ‘timeout’ => ‘2d’ }.

If the expression has an :await attribute, the expression gets into a special "awaiting" state until the condition in the value of :await gets triggered and the trigger calls resume on the expression.

This default implementation cancels all the [registered] children of this expression.

Emits a cancel message for each flanking expression (if any).

Given an index, returns the child fei (among the currently registered children feis) whose fei.expid ends with this index (whose child_id is equal to that index).

Returns nil if not found or a child fei as a Hash.

Returns the child_id for this expression. (The rightmost part of the fei.expid).

Returns the list of child_ids (last part of the fei.expid) for the currently registered (active) children.

Returns a Hash containing all attributes set for an expression with their values resolved.

Returns a fresh hash of all the variables visible from this expression.

This is used mainly when forgetting an expression.

Outputs ids like "0_2!d218c1b", no wfid, only <expid>!<subid>[0, 7]

Given this expression and an error, deflates the error into a hash (serializable).

Wraps a call to "apply", "reply", etc… Makes sure to set @msg with a deep copy of the msg before.

Called by the worker when it has just created this FlowExpression and wants to apply it.

The raw handling of messages passed to expressions (the fine handling is done in the cancel method).

Called when handling an on_error, will place itself in a ‘failing’ state and cancel the children (when the reply from the children comes back, the on_error will get triggered).

Expression received a "pause" message. Will put the expression in the "paused" state and then pass the message to the children.

If the expression is in a non-nil state (failed, timed_out, …), the message will be ignored.

Make sure to persist (retry if necessary).

do_receive(msg)

Alias for do_reply

Wraps reply (does the administrative part of the reply work).

Will "unpause" the expression (if it was paused), and trigger any ‘paused_replies’ (replies that came while the expression was paused).

Make sure to unpersist (retry if necessary).

Returns the Ruote::FlowExpressionId for this expression.

Looks up parent with on_error attribute and triggers it

has_att(*args)

Alias for has_attribute

Given a list of attribute names, returns the first attribute name for which there is a value.

Persists and fetches the _rev identifier from the storage.

Only used by the worker when creating the expression.

Concurrent expressions (expressions that apply more than one child at a time) are supposed to return true here.

TODO : rdoc rewrite needed

This method is mostly used by the worker when looking up a process name or participant name bound under a variable.

Launches a subprocesses (usually called from the apply of certain expression implementations.

prefix = ‘on’ => will lookup on, on_val, on_value, on_v, on_var, on_variable, on_f, on_fld, on_field…

Looks up the value of a variable in expression tree (seen from a leaf, it looks more like a stack than a tree)

lv(var, prefix=nil)

Alias for lookup_variable

Returns the name of this expression, like ‘sequence’, ‘participant’, ‘cursor’, etc…

Fetches the parent expression, or returns nil if there is no parent expression.

Returns the Ruote::FlowExpressionIf of the parent expression, or nil if there is no parent expression.

Called by do_apply when msg[‘state’] == ‘paused’. Covers the "apply/launch it but it‘s immediately paused" case. Freezes the apply message in h.paused_apply and saves the expression.

persist()

Alias for persist_or_raise

A default implementation for all the expressions.

FlowExpression call this method when they‘re done and they want their parent expression to take over (it will end up calling the reply of the parent expression).

Expression implementations are free to override this method. The common behaviour is in do_reply_to_parent.

An expensive method, looks up all the expressions with the same wfid in the storage (for some storages this is not expensive at all), and determine the root of this expression. It does this by recursively going from an expression to its parent, starting with this expression. The root is when the parent can‘t be reached.

By default, this method will always return an expression, but if stubborn is set to true and the top expression points to a gone parent then nil will be returned. The default (stubborn=true) is probably what you want anyway.

Returns the fei of the root expression of this expression. The result is an instance of Ruote::FlowExpressionId.

Uses root behind the scenes, hence the stubborn option.

Sets a variable to a given value. (will set at the appropriate level).

Turns this FlowExpression instance into a Hash (well, just hands back the base hash behind it).

Returns the current version of the tree (returns the updated version if it got updated.

Returns the "AST" view on the children of this expression…

unpersist()

Alias for unpersist_or_raise

Updates the tree of this expression

  update_tree(t)

will set the updated tree to t

  update_tree

will copy (deep copy) the original tree as the updated_tree.

Adding a child to a sequence expression :

  seq.update_tree
  seq.updated_tree[2] << [ 'participant', { 'ref' => 'bob' }, [] ]
  seq.do_persist
v(var, prefix=nil)

Alias for lookup_variable

A shortcut to the variables held in the expression (nil if none held).

Returns the workflow instance id of the workflow this expression belongs to.

Protected Instance methods

Used by expressions when, well, applying a child expression of theirs.

Called to check if the expression has a :tag attribute. If yes, will register the tag in a variable (and in the workitem).

Reads the :timeout and :timers attributes and schedule as necessary.

‘tos’ meaning ‘many "to"’

Does persist or unpersist, if successful then returns true. If the expression is gone, returns false. If there is a ‘fresher’ version of the expression, re-attempt and returns false.

dollar substitution for expressions.

The :filter attribute work is done here, at apply (in) and at reply (out).

Called when the expression is about to reply to its parent and wants to get rid of its tags.

Given an error, returns the on_error registered for it, or nil if none.

When used with override = true(ish), will try to locate the binding site for the variable and return it.

If override is set to ‘sub’, will stop before digging into the parent subprocess.

Returns the flow expression that owns a variable (or the one that should own it) and the var without its potential / prefixes.

In other words:

  [ owner, varname_without_slashes ]

When a location for the variable could not be found, it returns:

  [ nil, nil ]

Used by filter, deals with the various ways to pass filters (directly, via a variable, via a participant, in and out, …)

Returns nil, if there is no filter. Raises an ArgumentError if the filter is not usable. Returns the instantiated participant if the filter points to a participant filter.

Looks up "on_error" attribute locally and in the parent expressions, if any.

Called successively to dig for the filter (Array or Participant).

Does persist or unpersist, returns nothing in particular.

Will raise a runtime error if it fails (ie if it happens, there is something wrong with the storage implementation or the engine).

Used locally but also by ConcurrenceExpression, when preparing children before they get applied.

Some expressions have to keep track of their (instantiated) children, this method does the registration (of the child‘s fei).

Called by trigger when it encounters something like

  :on_error => '5m: retry, pass'

Used by consider_timers and ParticipantExpression#consider_participant_timers

Takes care of registering the timers/timeout for an expression.

Used by lookup_variable and set_variable to extract the prefix in a variable name

Returns a Graphviz dot string representing this expression (and its children).

‘on_{error|timeout|cancel|re_apply}’ triggering

Sets (or unsets) the value of a local variable

val should be nil in case of ‘unset’.

[Validate]