lib/openwfe/expressions/time.rb in openwferu-0.9.15 vs lib/openwfe/expressions/time.rb in openwferu-0.9.16
- old
+ new
@@ -51,19 +51,30 @@
# localization for <sleep/> and <cron/>.
#
class TimeExpression < FlowExpression
include Schedulable
- attr_accessor \
- :applied_workitem,
- :scheduler_job_id
+ #
+ # The workitem received at apply time
+ #
+ attr_accessor :applied_workitem
#
+ # The job_id in the scheduler for this expression
+ #
+ attr_accessor :scheduler_job_id
+
+ #
+ # The tags (if any) for the job in the scheduler
+ #
+ attr_accessor :scheduler_tags
+
+ #
# Makes sure to cancel any scheduler job associated with this
# expression
#
- def cancel ()
+ def cancel
synchronize do
ldebug { "cancel()..." }
unschedule()
@@ -76,27 +87,42 @@
#
# If the expression has been scheduled, a call to this method
# will make sure it's unscheduled (removed from the scheduler).
#
- def unschedule ()
+ def unschedule
ldebug { "unschedule() @scheduler_job_id is #{@scheduler_job_id}" }
get_scheduler.unschedule(@scheduler_job_id) \
if @scheduler_job_id
end
+
+ protected
+
+ def determine_scheduler_tags
+
+ st = lookup_attribute :scheduler_tags, @applied_workitem
+
+ @scheduler_tags = if st
+ st.split(",").collect { |s| s.strip }
+ else
+ []
+ end
+ @scheduler_tags << self.class.name
+ end
end
#
# A parent class for WhenExpression and WaitExpression.
#
# All the code for managing waiting for something to occur is
# concentrated here.
#
class WaitingExpression < TimeExpression
- include ConditionMixin, TimeoutMixin
+ include ConditionMixin
+ include TimeoutMixin
attr_accessor :frequency
#
# By default, classes extending this class do poll for their
@@ -117,24 +143,25 @@
end
end
def apply (workitem)
- remove_timedout_flag(workitem)
+ remove_timedout_flag workitem
@applied_workitem = workitem.dup
- @frequency =
- lookup_attribute(:frequency, workitem, DEFAULT_FREQUENCY)
- @frequency =
- OpenWFE::parse_time_string(@frequency)
+ @frequency = lookup_attribute(
+ :frequency, workitem, :default => DEFAULT_FREQUENCY)
+ @frequency = OpenWFE::parse_time_string(
+ @frequency)
- determine_timeout()
+ determine_timeout
+ determine_scheduler_tags
- store_itself()
+ store_itself
- trigger()
+ trigger
end
def reply (workitem)
result = workitem.get_result
@@ -174,10 +201,13 @@
@scheduler_job_id = "waiting_#{fei.to_s}"
scheduler.schedule_in(
@frequency,
- { :schedulable => self, :job_id => @scheduler_job_id })
+ {
+ :schedulable => self,
+ :job_id => @scheduler_job_id,
+ :tags => @scheduler_tags })
ldebug { "reschedule() @scheduler_job_id is #{@scheduler_job_id}" }
to_reschedule(scheduler)
end