lib/openwfe/expressions/fe_when.rb in openwferu-0.9.7 vs lib/openwfe/expressions/fe_when.rb in openwferu-0.9.8
- old
+ new
@@ -37,21 +37,20 @@
# "made in Japan"
#
# John Mettraux at openwfe.org
#
-#require 'openwfe/rudefinitions'
require 'openwfe/utils'
require 'openwfe/util/otime'
require 'openwfe/util/scheduler'
+require 'openwfe/expressions/time'
require 'openwfe/expressions/timeout'
require 'openwfe/expressions/condition'
-require 'openwfe/expressions/fe_sleep'
#
-# expressions like 'sleep' and 'cron'
+# 'when' and 'wait'
#
module OpenWFE
#
@@ -63,131 +62,67 @@
# </when>
#
# where the participant "toto" will receive a workitem when the (local)
# variable "over" has the value true.
#
- class WhenExpression < TimeExpression
- include ConditionMixin, TimeoutMixin
+ # 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.
+ #
+ class WhenExpression < WaitingExpression
names :when
+ conditions :test
attr_accessor \
- :frequency,
- :consequence_triggered
+ :consequence_triggered,
+ :condition_sub_id
DEFAULT_FREQUENCY = "10s"
def apply (workitem)
- remove_timedout_flag(workitem)
-
if @children.size < 1
- reply_to_parent(workitem)
+ reply_to_parent workitem
return
end
- @applied_workitem = workitem.dup
-
- @frequency =
- lookup_attribute(:frequency, workitem, DEFAULT_FREQUENCY)
- @frequency =
- OpenWFE::parse_time_string(@frequency)
-
- determine_timeout()
-
+ @condition_sub_id = -1
@consequence_triggered = false
- store_itself()
-
- trigger(nil)
+ super(workitem)
end
def reply (workitem)
- ldebug do
- "reply() @consequence_triggered is '#{@consequence_triggered}'"
- end
+ #ldebug do
+ # "reply() @consequence_triggered is '#{@consequence_triggered}'"
+ #end
if @consequence_triggered
reply_to_parent(workitem)
return
end
- result = OpenWFE::get_result(workitem)
-
- if result
- apply_consequence(workitem)
- else
- reschedule(get_scheduler)
- end
- end
-
- def cancel ()
- to_unschedule()
- super()
- end
-
- def trigger (params)
-
- ldebug { "trigger() #{@fei.to_debug_s} params is #{params}" }
-
- if params == :do_timeout!
- #
- # do timeout...
- #
- set_timedout_flag(@applied_workitem)
- reply_to_parent(@applied_workitem)
- return
- end
-
- @scheduler_job_id = nil
-
- evaluate_condition()
- end
-
- def reschedule (scheduler)
-
- #return unless @applied_workitem
-
- @scheduler_job_id =
- scheduler.schedule_in(@frequency, self, nil)
-
- ldebug { "reschedule() @scheduler_job_id is #{@scheduler_job_id}" }
-
- to_reschedule(scheduler)
- end
-
- def reply_to_parent (workitem)
-
- unschedule()
- unschedule_timeout()
-
super(workitem)
end
protected
-
- def evaluate_condition
-
- if @children.size > 1
- #
- # trigger the evaluation of the first (condition) child
-
- store_itself()
-
- get_expression_pool.launch_template(
- self, @children[0], @applied_workitem)
- else
- #
- # eval the attribute condition immediately
-
- c = eval_condition(:test, @applied_workitem)
-
- OpenWFE::set_result(@applied_workitem, c)
-
- reply(@applied_workitem)
- end
- end
def apply_consequence (workitem)
@consequence_triggered = true