lib/openwfe/expressions/timeout.rb in openwferu-0.9.3 vs lib/openwfe/expressions/timeout.rb in openwferu-0.9.4

- old
+ new

@@ -57,38 +57,72 @@ module TimeoutMixin include Schedulable attr_accessor \ :timeout_at, - :scheduler_job_id + :timeout_job_id def determine_timeout + #@timeout_at = nil + #@timeout_job_id = nil + timeout = lookup_attribute(:timeout, @applied_workitem) return unless timeout timeout = OpenWFE::parse_time_string(timeout) @timeout_at = Time.new.to_f + timeout - - reschedule(get_scheduler) end + # + # Overrides the parent method to make sure a potential + # def reschedule (scheduler) + to_reschedule(scheduler) + end - return unless @timeout_at + # + # Overrides the parent method to make sure a potential + # timeout schedules gets removed. + # + def reply_to_parent (workitem) + unschedule_timeout() + super(workitem) + end - @scheduler_job_id = - scheduler.schedule_at(@timeout_at, self, nil) + protected - ldebug do - "reschedule() will timeout at "+ - "#{OpenWFE::to_iso8601_date(@timeout_at)}" + # + # prefixed with "to_" for easy mix in + # + def to_reschedule (scheduler) + + return if @timeout_job_id + # + # already rescheduled + + return unless @timeout_at + # + # no need for a timeout + + @timeout_job_id = + scheduler.schedule_at(@timeout_at, self, :do_timeout!) + + ldebug do + "to_reschedule() will timeout at "+ + "#{OpenWFE::to_iso8601_date(@timeout_at)}" + end + + #store_itself() + # + # done in the including expression end - #store_itself() - # - # done in the including expression - end + def unschedule_timeout () + + get_scheduler.unschedule(@timeout_job_id) \ + if @timeout_job_id + end end end