Class: OpenWFE::WhenExpression

Inherits:
WaitingExpression show all
Defined in:
lib/openwfe/expressions/fe_when.rb

Overview

The ‘when’ expression will trigger a consequence when a condition is met, like in

<when test="${variable:over} == true">
    <participant ref="toto" />
</when>

where the participant “toto” will receive a workitem when the (local) variable “over” has the value true.

This is also possible :

<when>
    <equals field-value="done" other-value="true" />
    <participant ref="toto" />
</when>

The ‘when’ expression by defaults, evaluates every 10 seconds its condition clause. A different frequency can be stated via the “frequency” attribute :

_when :test => "${completion_level} == 4", :frequency => "1s"
    participant "next_stage"
end

will check for the completion_level value every second. The scheduler itself is by default ‘waking up’ every 250 ms, so setting a frequency to something smaller than that value might prove useless. (Note than in the Ruby process definition, the ‘when’ got escaped to ‘_when’ not to conflict with the ‘when’ keyword of the Ruby language).

The when expression understands the ‘timeout’ attribute like the participant expression does. Thus

_when :test => "${cows} == 'do fly'", :timeout => "1y"
    participant "me"
end

will timeout after one year (participant “me” will not receive a workitem).

Constant Summary

Constants inherited from WaitingExpression

OpenWFE::WaitingExpression::DEFAULT_FREQUENCY, OpenWFE::WaitingExpression::MIN_FREQUENCY

Instance Attribute Summary collapse

Attributes inherited from WaitingExpression

#frequency

Attributes included from TimeoutMixin

#timeout_at, #timeout_job_id

Attributes inherited from TimeExpression

#applied_workitem, #scheduler_job_id, #scheduler_tags

Attributes inherited from FlowExpression

#apply_time, #attributes, #children, #environment_id, #fei, #parent_id, #raw_representation

Attributes included from Contextual

#application_context

Instance Method Summary collapse

Methods inherited from WaitingExpression

#cancel, conditions, #reply_to_parent, #reschedule, #trigger

Methods included from TimeoutMixin

#determine_timeout, #remove_timedout_flag, #reschedule, #schedule_timeout, #set_timedout_flag

Methods included from ConditionMixin

#determine_condition_attribute, #eval_condition

Methods inherited from TimeExpression

#cancel, #unschedule

Methods inherited from FlowExpression

#cancel, #clean_children, #delete_variable, #dup_environment, #fetch_environment, #fetch_text_content, #get_binding, #get_environment, #get_parent, #get_root_environment, #has_attribute, #initialize, is_definition, is_definition?, #lookup_attribute, #lookup_attributes, #lookup_boolean_attribute, #lookup_comma_list_attribute, #lookup_downcase_attribute, #lookup_ref, #lookup_string_attribute, #lookup_sym_attribute, #lookup_value, #lookup_variable, #lookup_vf_attribute, names, #new_environment, new_exp, #owns_its_environment?, #paused?, #remove_child, #reply_to_parent, #set_variable, #store_itself, #synchronize, #to_s, #to_yaml_properties

Methods included from Contextual

#get_work_directory, #init_service, #lookup

Methods included from Logging

#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn

Methods included from OwfeServiceLocator

#get_engine, #get_error_journal, #get_expool, #get_expression_map, #get_expression_pool, #get_expression_storage, #get_expression_storages, #get_journal, #get_participant_map, #get_scheduler, #get_wfid_generator

Methods inherited from ObjectWithMeta

#class_def, meta_def, meta_eval, metaclass

Constructor Details

This class inherits a constructor from OpenWFE::FlowExpression

Instance Attribute Details

#condition_sub_idObject

Returns the value of attribute condition_sub_id.



99
100
101
# File 'lib/openwfe/expressions/fe_when.rb', line 99

def condition_sub_id
  @condition_sub_id
end

#consequence_triggeredObject

Returns the value of attribute consequence_triggered.



99
100
101
# File 'lib/openwfe/expressions/fe_when.rb', line 99

def consequence_triggered
  @consequence_triggered
end

Instance Method Details

#apply(workitem) ⇒ Object



103
104
105
106
107
108
109
110
111
112
# File 'lib/openwfe/expressions/fe_when.rb', line 103

def apply (workitem)

    return reply_to_parent(workitem) \
        if @children.size < 1

    @condition_sub_id = -1
    @consequence_triggered = false

    super workitem
end

#reply(workitem) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/openwfe/expressions/fe_when.rb', line 114

def reply (workitem)

    #ldebug do 
    #    "reply() @consequence_triggered is '#{@consequence_triggered}'"
    #end

    return reply_to_parent(workitem) \
        if @consequence_triggered

    super workitem
end