lib/openwfe/expressions/time.rb in openwferu-0.9.16 vs lib/openwfe/expressions/time.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,12 +35,11 @@ # "made in Japan" # # John Mettraux at openwfe.org # -require 'openwfe/util/otime' -require 'openwfe/util/scheduler' +require 'rufus/otime' require 'openwfe/expressions/timeout' module OpenWFE @@ -49,11 +48,11 @@ # used directly. # It contains a simple get_scheduler() method simplifying the scheduler # localization for <sleep/> and <cron/>. # class TimeExpression < FlowExpression - include Schedulable + include Rufus::Schedulable # # The workitem received at apply time # attr_accessor :applied_workitem @@ -91,16 +90,25 @@ # def unschedule ldebug { "unschedule() @scheduler_job_id is #{@scheduler_job_id}" } + sleep get_scheduler.precision + 0.001 + # + # make sure not to unschedule before the actual scheduling + # got done. + get_scheduler.unschedule(@scheduler_job_id) \ if @scheduler_job_id end protected + # + # looks up potential scheduler tags in the expression + # attributes + # def determine_scheduler_tags st = lookup_attribute :scheduler_tags, @applied_workitem @scheduler_tags = if st @@ -129,14 +137,20 @@ # condition every 10 seconds. # DEFAULT_FREQUENCY = "10s" # + # Don't go under 300 milliseconds. + # + MIN_FREQUENCY = 0.300 + + # # Classes extending this WaitingExpression have a 'conditions' class # method (like 'attr_accessor'). # def self.conditions (*attnames) + attnames = attnames.collect do |n| n.to_s.intern end meta_def :condition_attributes do attnames @@ -149,12 +163,14 @@ @applied_workitem = workitem.dup @frequency = lookup_attribute( :frequency, workitem, :default => DEFAULT_FREQUENCY) - @frequency = OpenWFE::parse_time_string( + @frequency = Rufus::parse_time_string( @frequency) + @frequency = MIN_FREQUENCY \ + if @frequency < MIN_FREQUENCY determine_timeout determine_scheduler_tags store_itself @@ -171,19 +187,23 @@ else reschedule(get_scheduler) end end - def cancel () + # + # Cancels this expression (takes care of unscheduling a timeout + # if there is one). + # + def cancel - to_unschedule() + unschedule_timeout super() end def trigger (params={}) - ldebug { "trigger() #{@fei.to_debug_s} params is #{params}" } + ldebug { "trigger() #{@fei.to_debug_s} params : #{params.inspect}" } if params[:do_timeout!] # # do timeout... # @@ -213,14 +233,14 @@ to_reschedule(scheduler) end def reply_to_parent (workitem) - unschedule() - unschedule_timeout() + unschedule + unschedule_timeout - super(workitem) + super workitem end protected # @@ -253,10 +273,14 @@ end # trigger the first child (the condition child) get_expression_pool.launch_template( - self, @condition_sub_id, @children[0], @applied_workitem) + self, + @environment_id, + @condition_sub_id, + @children[0], + @applied_workitem) end # # Used when replying to self after an attribute condition # got evaluated