Class OpenWFE::SleepExpression
In: lib/openwfe/expressions/fe_sleep.rb
Parent: TimeExpression

The ‘sleep’ expression expects one attribute, either ‘for’, either ‘until’.

    <sequence>
        <sleep for="10m12s" />
        <participant ref="alpha" />
    </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.

Methods

apply   reschedule   trigger  

Attributes

awakening_time  [RW] 

Public Instance methods

[Source]

     # File lib/openwfe/expressions/fe_sleep.rb, line 79
 79:         def apply (workitem)
 80: 
 81:             sfor = lookup_string_attribute(:for, workitem)
 82:             suntil = lookup_string_attribute(:until, workitem)
 83: 
 84:             sfor = fetch_text_content(workitem) \
 85:                 if sfor == nil and suntil == nil
 86: 
 87:             #ldebug { "apply() sfor is '#{sfor}'" }
 88:             #ldebug { "apply() suntil is '#{suntil}'" }
 89: 
 90:             tuntil = nil
 91: 
 92:             if suntil
 93: 
 94:                 tuntil = suntil
 95: 
 96:             elsif sfor
 97: 
 98:                 tfor = Rufus::parse_time_string(sfor)
 99:                 #ldebug { "apply() tfor is '#{tfor}'" }
100:                 tuntil = Time.new.to_f + tfor
101:             end
102: 
103:             #ldebug { "apply() tuntil is '#{tuntil}'" }
104: 
105:             return reply_to_parent(workitem) \
106:                 if not tuntil
107: 
108:             @awakening_time = tuntil
109:             @applied_workitem = workitem.dup
110: 
111:             determine_scheduler_tags
112: 
113:             reschedule(get_scheduler)
114:         end

[Re]schedules this expression, effectively registering it within the scheduler. This method is called when the expression is applied and each time the owning engine restarts.

[Source]

     # File lib/openwfe/expressions/fe_sleep.rb, line 137
137:         def reschedule (scheduler)
138: 
139:             return unless @awakening_time
140: 
141:             ldebug do 
142:                 "[re]schedule() " + 
143:                 "will sleep until '#{@awakening_time}' " +
144:                 "(#{Rufus::to_iso8601_date(@awakening_time)})"
145:             end
146: 
147:             @scheduler_job_id = "sleep_#{self.fei.to_s}"
148:             
149:             scheduler.schedule_at(
150:                 @awakening_time,
151:                 { 
152:                     :schedulable => self, 
153:                     :job_id => @scheduler_job_id,
154:                     :tags => @scheduler_tags })
155: 
156:             ldebug do 
157:                 "[re]schedule() @scheduler_job_id is '#{@scheduler_job_id}' "+
158:                 " (scheduler #{scheduler.object_id})"
159:             end
160: 
161:             store_itself
162:         end

This is the method called by the Scheduler instance attached to the workflow engine when the ‘sleep’ of this expression is over

[Source]

     # File lib/openwfe/expressions/fe_sleep.rb, line 121
121:         def trigger (params)
122: 
123:             ldebug do 
124:                 "trigger() #{@fei.to_debug_s} waking up (#{Time.new.to_f}) "+
125:                 "(scheduler #{get_scheduler.object_id})"
126:             end
127: 
128:             reply_to_parent(@applied_workitem)
129:         end

[Validate]