lib/openwfe/expressions/fe_sleep.rb in openwferu-0.9.16 vs lib/openwfe/expressions/fe_sleep.rb in openwferu-0.9.17
- old
+ new
@@ -1,8 +1,8 @@
#
#--
-# Copyright (c) 2006-2007, John Mettraux, OpenWFE.org
+# Copyright (c) 2006-2008, John Mettraux, OpenWFE.org
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
@@ -35,19 +35,14 @@
# "made in Japan"
#
# John Mettraux at openwfe.org
#
-require 'openwfe/util/otime'
-require 'openwfe/util/scheduler'
+require 'rufus/otime'
require 'openwfe/expressions/time'
-#
-# just the 'sleep' expression
-#
-
module OpenWFE
#
# The 'sleep' expression expects one attribute, either 'for', either
# 'until'.
@@ -58,16 +53,30 @@
# </sequence>
#
# will wait for 10 minutes and 12 seconds before sending a workitem
# to participant 'alpha'.
#
+ # In a Ruby process definition, that might look like :
+ #
+ # sleep :for => "3m"
+ # sleep "3m"
+ # #
+ # # both meaning 'sleep for 3 minutes'
+ #
+ # sleep :until => "Mon Dec 03 10:41:58 +0900 2007"
+ # #
+ # # sleep until the given point in time
+ #
+ # If the 'until' attribute points to a time in the past, the sleep
+ # expression will simply let the process resume.
+ #
+ #
class SleepExpression < TimeExpression
names :sleep
- attr_accessor \
- :awakening_time
+ attr_accessor :awakening_time
def apply (workitem)
sfor = lookup_string_attribute(:for, workitem)
suntil = lookup_string_attribute(:until, workitem)
@@ -79,23 +88,24 @@
#ldebug { "apply() suntil is '#{suntil}'" }
tuntil = nil
if suntil
+
tuntil = suntil
+
elsif sfor
- tfor = OpenWFE::parse_time_string(sfor)
+
+ tfor = Rufus::parse_time_string(sfor)
#ldebug { "apply() tfor is '#{tfor}'" }
tuntil = Time.new.to_f + tfor
end
#ldebug { "apply() tuntil is '#{tuntil}'" }
- if not tuntil
- reply_to_parent(workitem)
- return
- end
+ return reply_to_parent(workitem) \
+ if not tuntil
@awakening_time = tuntil
@applied_workitem = workitem.dup
determine_scheduler_tags
@@ -129,10 +139,10 @@
return unless @awakening_time
ldebug do
"[re]schedule() " +
"will sleep until '#{@awakening_time}' " +
- "(#{OpenWFE::to_iso8601_date(@awakening_time)})"
+ "(#{Rufus::to_iso8601_date(@awakening_time)})"
end
@scheduler_job_id = "sleep_#{self.fei.to_s}"
scheduler.schedule_at(