Class OpenWFE::WaitingExpression
In: lib/openwfe/expressions/time.rb
Parent: TimeExpression

A parent class for WhenExpression and WaitExpression.

All the code for managing waiting for something to occur is concentrated here.

Methods

Included Modules

ConditionMixin TimeoutMixin

Constants

DEFAULT_FREQUENCY = "10s"   By default, classes extending this class do poll for their condition every 10 seconds.
MIN_FREQUENCY = 0.300   Don‘t go under 300 milliseconds.

Attributes

frequency  [RW] 

Public Class methods

Classes extending this WaitingExpression have a ‘conditions’ class method (like ‘attr_accessor’).

[Source]

     # File lib/openwfe/expressions/time.rb, line 150
150:         def self.conditions (*attnames)
151: 
152:             attnames = attnames.collect do |n|
153:                 n.to_s.intern
154:             end
155:             meta_def :condition_attributes do
156:                 attnames
157:             end
158:         end

Public Instance methods

[Source]

     # File lib/openwfe/expressions/time.rb, line 160
160:         def apply (workitem)
161: 
162:             remove_timedout_flag workitem
163: 
164:             @applied_workitem = workitem.dup
165: 
166:             @frequency = lookup_attribute(
167:                 :frequency, workitem, :default => DEFAULT_FREQUENCY)
168:             @frequency = Rufus::parse_time_string(
169:                 @frequency)
170:             @frequency = MIN_FREQUENCY \
171:                 if @frequency < MIN_FREQUENCY
172: 
173:             determine_timeout
174:             determine_scheduler_tags
175: 
176:             store_itself
177: 
178:             trigger
179:         end

Cancels this expression (takes care of unscheduling a timeout if there is one).

[Source]

     # File lib/openwfe/expressions/time.rb, line 196
196:         def cancel
197: 
198:             unschedule_timeout
199:             super()
200:         end

[Source]

     # File lib/openwfe/expressions/time.rb, line 181
181:         def reply (workitem)
182: 
183:             result = workitem.get_result
184: 
185:             if result
186:                 apply_consequence(workitem)
187:             else
188:                 reschedule(get_scheduler)
189:             end
190:         end

[Source]

     # File lib/openwfe/expressions/time.rb, line 236
236:         def reply_to_parent (workitem)
237: 
238:             unschedule
239:             unschedule_timeout
240: 
241:             super workitem
242:         end

[Source]

     # File lib/openwfe/expressions/time.rb, line 220
220:         def reschedule (scheduler)
221: 
222:             @scheduler_job_id = "waiting_#{fei.to_s}"
223: 
224:             scheduler.schedule_in(
225:                 @frequency, 
226:                 { 
227:                     :schedulable => self, 
228:                     :job_id => @scheduler_job_id,
229:                     :tags => @scheduler_tags })
230: 
231:             ldebug { "reschedule() @scheduler_job_id is #{@scheduler_job_id}" }
232: 
233:             to_reschedule(scheduler)
234:         end

[Source]

     # File lib/openwfe/expressions/time.rb, line 202
202:         def trigger (params={})
203: 
204:             ldebug { "trigger() #{@fei.to_debug_s} params : #{params.inspect}" }
205: 
206:             if params[:do_timeout!]
207:                 #
208:                 # do timeout...
209:                 #
210:                 set_timedout_flag @applied_workitem
211:                 reply_to_parent @applied_workitem
212:                 return
213:             end
214: 
215:             @scheduler_job_id = nil
216: 
217:             evaluate_condition()
218:         end

Protected Instance methods

This method is overriden by WhenExpression. WaitExpression doesn‘t override it. This default implementation simply directly replies to the parent expression.

[Source]

     # File lib/openwfe/expressions/time.rb, line 301
301:             def apply_consequence (workitem)
302: 
303:                 reply_to_parent workitem
304:             end

Used when replying to self after an attribute condition got evaluated

[Source]

     # File lib/openwfe/expressions/time.rb, line 289
289:             def do_reply (result)
290: 
291:                 @applied_workitem.set_result result
292:                 reply @applied_workitem
293:             end

The code for the condition evalution is here.

This method is overriden by the WhenExpression.

[Source]

     # File lib/openwfe/expressions/time.rb, line 251
251:             def evaluate_condition
252: 
253:                 condition_attribute = determine_condition_attribute(
254:                     self.class.condition_attributes)
255: 
256:                 if condition_attribute
257: 
258:                     c = eval_condition(condition_attribute, @applied_workitem)
259: 
260:                     do_reply c
261:                     return
262:                 end
263: 
264:                 # else, condition is nested as a child
265: 
266:                 if @children.size < 1
267:                     #
268:                     # no condition attribute and no child attribute,
269:                     # simply reply to parent
270:                     #
271:                     reply_to_parent @applied_workitem
272:                     return
273:                 end
274: 
275:                 # trigger the first child (the condition child)
276: 
277:                 get_expression_pool.launch_template(
278:                     self, 
279:                     @environment_id,
280:                     @condition_sub_id, 
281:                     @children[0], 
282:                     @applied_workitem)
283:             end

[Validate]