lib/rufus/sc/jobs.rb in rufus-scheduler-2.0.3 vs lib/rufus/sc/jobs.rb in rufus-scheduler-2.0.4
- old
+ new
@@ -1,7 +1,7 @@
#--
-# Copyright (c) 2006-2009, John Mettraux, jmettraux@gmail.com
+# Copyright (c) 2006-2010, John Mettraux, jmettraux@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -37,14 +37,14 @@
# The initial, raw, scheduling info (at / in / every / cron)
#
attr_reader :t
- # When the job is actually running, this attribute will hold the
- # thread in which the job is running.
+ # Returns the thread instance of the last triggered job.
+ # May be null (especially before the first trigger).
#
- attr_reader :job_thread
+ attr_reader :last_job_thread
# The job parameters (passed via the schedule method)
#
attr_reader :params
@@ -114,23 +114,25 @@
# Triggers the job.
#
def trigger (t=Time.now)
@last = t
+ job_thread = 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)
- @job_thread = Thread.current
+ job_thread = Thread.current
+ @last_job_thread = job_thread
begin
trigger_block
- @job_thread = nil
+ job_thread = nil
rescue Exception => e
@scheduler.handle_exception(self, e)
end
@@ -143,11 +145,11 @@
@scheduler.in(to, :tags => 'timeout') do
# at this point, @job_thread might be set
- @job_thread.raise(Rufus::Scheduler::TimeOutError) \
- if @job_thread and @job_thread.alive?
+ job_thread.raise(Rufus::Scheduler::TimeOutError) \
+ if job_thread && job_thread.alive?
end
end
end
# Simply encapsulating the block#call/trigger operation, for easy