lib/openwfe/expressions/fe_time.rb in openwferu-0.9.4 vs lib/openwfe/expressions/fe_time.rb in openwferu-0.9.5
- old
+ new
@@ -42,11 +42,11 @@
require 'openwfe/rudefinitions'
require 'openwfe/utils'
require 'openwfe/util/otime'
require 'openwfe/util/scheduler'
require 'openwfe/expressions/timeout'
-require 'openwfe/expressions/fe_condition'
+require 'openwfe/expressions/condition'
#
# expressions like 'sleep' and 'cron'
#
@@ -106,35 +106,35 @@
attr_accessor \
:awakening_time
def apply (workitem)
- synchronize do
+ #synchronize do
- sfor = lookup_attribute(:for, workitem)
- suntil = lookup_attribute(:until, workitem)
+ sfor = lookup_attribute(:for, workitem)
+ suntil = lookup_attribute(:until, workitem)
- tuntil = nil
+ tuntil = nil
- if suntil
- tuntil = suntil
- elsif sfor
- tfor = OpenWFE::parse_time_string(sfor)
- ldebug { "apply() tfor is '#{tfor}'" }
- tuntil = Time.new.to_f + tfor
- end
+ if suntil
+ tuntil = suntil
+ elsif sfor
+ tfor = OpenWFE::parse_time_string(sfor)
+ ldebug { "apply() tfor is '#{tfor}'" }
+ tuntil = Time.new.to_f + tfor
+ end
- if not tuntil
- reply_to_parent(workitem)
- return
- end
+ if not tuntil
+ reply_to_parent(workitem)
+ return
+ end
- @awakening_time = tuntil
- @applied_workitem = workitem.dup
+ @awakening_time = tuntil
+ @applied_workitem = workitem.dup
- reschedule(get_scheduler)
- end
+ reschedule(get_scheduler)
+ #end
end
#def reply (workitem)
#end
@@ -157,10 +157,12 @@
# This method is called when the expression is applied and each
# time the owning engine restarts.
#
def reschedule (scheduler)
+ return unless @awakening_time
+
ldebug do
"[re]schedule() " +
"will sleep until '#{@awakening_time}' " +
"(#{OpenWFE::to_iso8601_date(@awakening_time)})"
end
@@ -195,14 +197,16 @@
# restarts).
#
class CronExpression < TimeExpression
attr_accessor \
- :raw_child, :tab, :name
+ :raw_child, :tab, :name, :counter
def apply (workitem)
+ @counter = 0
+
if @children.size < 1
reply_to_parent(workitem)
return
end
@@ -227,11 +231,11 @@
#
# store self as a variable
# (have to do it after the reschedule, so that the schedule
# info is stored within the variable)
- set_variable(@name, self)
+ set_variable(@name, self) if @name
#
# resume flow
reply_to_parent(workitem)
@@ -258,12 +262,21 @@
ldebug { "trigger() cron : #{@fei.to_debug_s}" }
@raw_child.application_context = @application_context
begin
+
get_expression_pool.launch_template(
- @fei.wfid, @raw_child, @applied_workitem.dup)
+ @fei.wfid, @counter, @raw_child, @applied_workitem.dup)
+
+ #
+ # update count and store self
+
+ @counter += 1
+
+ set_variable(@name, self) if @name
+
rescue
lerror do
"trigger() cron caught exception\n"+
OpenWFE::exception_to_s($!)
end
@@ -275,10 +288,12 @@
# or each time the engine is restarted and this expression has
# to be rescheduled.
#
def reschedule (scheduler)
+ #return unless @applied_workitem
+
@scheduler_job_id = @name.dup
@scheduler_job_id = "#{@fei.wfid}__#{@scheduler_job_id}" \
if not OpenWFE::starts_with(@name, "//")
@@ -312,10 +327,12 @@
DEFAULT_FREQUENCY = "20s"
def apply (workitem)
+ remove_timedout_flag(workitem)
+
if @children.size < 1
reply_to_parent(workitem)
return
end
@@ -364,19 +381,22 @@
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}" }