lib/rufus/sc/jobs.rb in rufus-scheduler-2.0.5 vs lib/rufus/sc/jobs.rb in rufus-scheduler-2.0.6
- old
+ new
@@ -115,10 +115,11 @@
#
def trigger (t=Time.now)
@last = t
job_thread = nil
+ to_job = nil
@scheduler.send(:trigger_job, @params[:blocking]) do
#
# Note that #trigger_job is protected, hence the #send
# (Only jobs know about this method of the scheduler)
@@ -129,10 +130,11 @@
begin
trigger_block
job_thread = nil
+ to_job.unschedule if to_job
rescue Exception => e
@scheduler.handle_exception(self, e)
end
@@ -141,16 +143,17 @@
# note that add_job and add_cron_job ensured that :blocking is
# not used along :timeout
if to = @params[:timeout]
- @scheduler.in(to, :tags => 'timeout') do
+ to_job = @scheduler.in(to, :parent => self, :tags => 'timeout') do
# at this point, @job_thread might be set
- job_thread.raise(Rufus::Scheduler::TimeOutError) \
- if job_thread && job_thread.alive?
+ if job_thread && job_thread.alive?
+ job_thread.raise(Rufus::Scheduler::TimeOutError)
+ end
end
end
end
# Simply encapsulating the block#call/trigger operation, for easy
@@ -166,30 +169,10 @@
#
def unschedule
@scheduler.unschedule(self.job_id)
end
-
- #--
- #protected
- #
- # Prepare the args given the triggered block arity.
- #
- #def prepare_args
- # if @scheduler.options[:onezero_block_arity]
- # case @block.arity
- # when 0 then []
- # when 1 then [ @params ]
- # when 2 then [ @job_id, @params ]
- # #else [ @job_id, schedule_info, @params ]
- # else [ @job_id, self, @params ]
- # end
- # else
- # [ self ]
- # end
- #end
- #++
end
#
# The base class of at/in/every jobs.
#
@@ -217,10 +200,20 @@
#
# Job that occurs once, in a certain amount of time.
#
class InJob < SimpleJob
+ # If this InJob is a timeout job, parent points to the job that
+ # is subject to the timeout.
+ #
+ attr_reader :parent
+
+ def initialize (scheduler, t, params)
+ @parent = params[:parent]
+ super
+ end
+
protected
def determine_at
iin = @t.is_a?(Fixnum) || @t.is_a?(Float) ?
@@ -256,12 +249,9 @@
def trigger
schedule_next
super
-
- #unschedule if @params[:dont_reschedule]
- # obsolete
end
protected
def determine_frequency