Class: Ruote::Exp::AddBranchesExpression

Inherits:
FlowExpression show all
Includes:
IteratorMixin
Defined in:
lib/ruote/exp/fe_add_branches.rb

Overview

The 'add_branches'/'add_branch' expression can be used to add branches to a concurrent-iterator while it is running.

concurrent_iterator :on => 'a, b, c' do
  sequence do
    participant :ref => 'worker_${v:i}'
    add_branches 'd, e', :if => '${v:/not_sufficient}'
  end
end

In this example, if the process level variable 'not_sufficient' is set to true, workers d and e will be added to the iterated elements.

'add_branches' understand comma-separated list of values or direcltly array of values, like the concurrent_iterator does. The :sep or :separator attribute can be used for custom separators :

add_branches 'd|e|f', :sep => '|'

:ref

By default, add_branches looks up the first parent expression that is concurrent_iterator. This is all well, but what when you have nested concurrent_iterator and want to hit the enclosing one from inside the enclosed one ? Or when you want to add branches from somewhere else in the process instance, outside of the concurrent_iterator ?

concurrence do

  concurrent_iterator :on => 'a, b, c', :tag => 'main' do
    subprocess :ref => 'perform_work'
  end

  sequence do
    subprocess :ref => 'supervise_work'
    add_branches 'd, e', :ref => 'main', :if => '${f:more_cowbell}'
    rewind :if => '${f:more_cowbell}'
  end
end

The add_branches expression refers to the 'main' concurrent_iterator via the :ref => 'main' attribute.

missing concurrent_iterator

If :ref points to nothing or add_branch has no :ref and is not placed inside of a concurrent_iterator, the expression will silently have no effect.

Constant Summary

Constant Summary

Constants inherited from FlowExpression

FlowExpression::COMMON_ATT_KEYS

Instance Attribute Summary

Attributes inherited from FlowExpression

#context, #error

Instance Method Summary collapse

Methods inherited from FlowExpression

#ancestor?, #applied_workitem, #att, #att_text, #attribute, #attribute_text, #attributes, #await, #cancel, #cancel_flanks, #cfei_at, #child_id, #child_ids, #compile_atts, #compile_variables, #debug_id, #deflate, #do, do_action, #do_apply, #do_cancel, #do_fail, #do_pause, #do_persist, #do_reply, #do_reply_to_parent, #do_resume, #do_unpersist, dummy, #fei, fetch, from_h, #handle_on_error, #has_attribute, #initial_persist, #initialize, #is_concurrent?, #iterative_var_lookup, #launch_sub, #lookup_val, #lookup_val_prefix, #lookup_variable, #name, names, #parent, #parent_id, #pause_on_apply, #persist_or_raise, #reply_to_parent, #root, #root_id, #set_variable, #tree, #tree_children, #try_persist, #try_unpersist, #unpersist_or_raise, #unset_variable, #update_tree, #variables, #wfid

Methods included from WithMeta

#class_def, included

Methods included from WithH

#h, #h=, included, #to_h

Constructor Details

This class inherits a constructor from Ruote::Exp::FlowExpression

Instance Method Details

#applyObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/ruote/exp/fe_add_branches.rb', line 88

def apply

  list = split_list(lookup_val_prefix('on') || attribute_text)
  it_fei = find_concurrent_iterator

  if list && it_fei

    wi = Ruote.fulldup(h.applied_workitem)
    wi['fields'][ConcurrentIteratorExpression::ADD_BRANCHES_FIELD] = list

    @context.storage.put_msg('reply', 'fei' => it_fei, 'workitem' => wi)
  end

  reply_to_parent(h.applied_workitem)
end

#reply(workitem) ⇒ Object



104
105
106
107
# File 'lib/ruote/exp/fe_add_branches.rb', line 104

def reply(workitem)

  # never called
end