Object
The base class for all types of jobs.
Instantiating the job.
# File lib/rufus/sc/jobs.rb, line 72 def initialize(scheduler, t, params, &block) @scheduler = scheduler @t = t @params = params @block = block || params[:schedulable] @running = false raise ArgumentError.new( 'no block or :schedulable passed, nothing to schedule' ) unless @block @params[:tags] = Array(@params[:tags]) @job_id = params[:job_id] || "#{self.class.name}_#{self.object_id.to_s}" determine_at end
Returns true if this job is currently running (in the middle of trigger)
# File lib/rufus/sc/jobs.rb, line 94 def running @running end
Generally returns the string/float/integer used to schedule the job (seconds, time string, date string)
# File lib/rufus/sc/jobs.rb, line 119 def schedule_info @t end
Triggers the job.
# File lib/rufus/sc/jobs.rb, line 126 def trigger(t=Time.now) @last = t job_thread = nil to_job = nil return if @running and (params[:allow_overlapping] == false) @running = true @scheduler.send(:trigger_job, @params) 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[ "rufus_scheduler__trigger_thread__#{@scheduler.object_id}" ] = true @last_job_thread = job_thread begin trigger_block job_thread = nil to_job.unschedule if to_job rescue Exception => e @scheduler.do_handle_exception(self, e) end @running = false end # note that add_job and add_cron_job ensured that :blocking is # not used along :timeout if to = @params[:timeout] to_job = @scheduler.in(to, :parent => self, :tags => 'timeout') do # at this point, @job_thread might be set if job_thread && job_thread.alive? job_thread.raise(Rufus::Scheduler::TimeOutError) end end end end
Generated with the Darkfish Rdoc Generator 2.