class Rufus::Scheduler::Job
The base class for all types of jobs.
def initialize (scheduler, t, params, &block)
Instantiating the job.
def initialize (scheduler, t, params, &block) @scheduler = scheduler @t = t @params = params @block = block || params[:schedulable] 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
def schedule_info
(seconds, time string, date string)
Generally returns the string/float/integer used to schedule the job
def schedule_info @t end
def tags
Returns the list of tags attached to the job.
def tags @params[:tags] end
def tags= (tags)
via the schedule every/at/in/cron method).
Sets the list of tags attached to the job (Usually they are set
def tags= (tags) @params[:tags] = Array(tags) end
def trigger (t=Time.now)
Triggers the job.
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) job_thread = Thread.current @last_job_thread = job_thread begin trigger_block job_thread = nil to_job.unschedule if to_job rescue Exception => e @scheduler.handle_exception(self, e) end 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
def trigger_block
override.
Simply encapsulating the block#call/trigger operation, for easy
def trigger_block @block.respond_to?(:call) ? @block.call(self) : @block.trigger(@params.merge(:job => self)) end
def unschedule
Unschedules this job.
def unschedule @scheduler.unschedule(self.job_id) end