Class Rufus::Scheduler::Job

  1. lib/rufus/sc/jobs.rb
Parent: Object

The base class for all types of jobs.

Methods

public class

  1. new

public instance

  1. schedule_info
  2. tags
  3. tags=
  4. trigger
  5. unschedule

Attributes

block [R] The block to call when triggering
job_id [R] The identifier for this job.
job_thread [R] When the job is actually running, this attribute will hold the thread in which the job is running. Can be used to determine if a job is actually running.
last [R] Last time the job executed (for an {At|In}Job, it will mean ‘not executed’ if nil or when it got executed if set)

( Last time job got triggered (most useful with EveryJob, but can be useful with remaining instances of At/InJob (are they done ?)) )

params [R] The job parameters (passed via the schedule method)
scheduler [R] A reference to the scheduler owning this job
t [R] The initial, raw, scheduling info (at / in / every / cron)

Public class methods

new (scheduler, t, params, &block)

Instantiating the job.

[show source]
    # File lib/rufus/sc/jobs.rb, line 74
74:     def initialize (scheduler, t, params, &block)
75: 
76:       @scheduler = scheduler
77:       @t = t
78:       @params = params
79:       @block = block || params[:schedulable]
80: 
81:       raise ArgumentError.new(
82:         'no block or :schedulable passed, nothing to schedule'
83:       ) unless @block
84: 
85:       @params[:tags] = Array(@params[:tags])
86: 
87:       @job_id = params[:job_id] || "#{self.class.name}_#{self.object_id.to_s}"
88: 
89:       determine_at
90:     end

Public instance methods

schedule_info ()

Generally returns the string/float/integer used to schedule the job (seconds, time string, date string)

[show source]
     # File lib/rufus/sc/jobs.rb, line 110
110:     def schedule_info
111: 
112:       @t
113:     end
tags ()

Returns the list of tags attached to the job.

[show source]
    # File lib/rufus/sc/jobs.rb, line 94
94:     def tags
95: 
96:       @params[:tags]
97:     end
tags= (tags)

Sets the list of tags attached to the job (Usually they are set via the schedule every/at/in/cron method).

[show source]
     # File lib/rufus/sc/jobs.rb, line 102
102:     def tags= (tags)
103: 
104:       @params[:tags] = Array(tags)
105:     end
trigger (t=Time.now)

Triggers the job.

[show source]
     # File lib/rufus/sc/jobs.rb, line 117
117:     def trigger (t=Time.now)
118: 
119:       @last = t
120: 
121:       @scheduler.send(:trigger_job, @params[:blocking]) do
122:         #
123:         # Note that #trigger_job is protected, hence the #send
124:         # (Only jobs know about this method of the scheduler)
125: 
126:         @job_thread = Thread.current
127: 
128:         begin
129: 
130:           #args = prepare_args
131:           #@block.call(*args)
132: 
133:           #@block.call(self)
134: 
135:           @block.respond_to?(:call) ?
136:             @block.call(self) : @block.trigger(@params)
137: 
138:           @job_thread = nil
139: 
140:         rescue Exception => e
141: 
142:           @scheduler.handle_exception(self, e)
143:         end
144:       end
145: 
146:       # note that add_job and add_cron_job ensured that :blocking is
147:       # not used along :timeout
148: 
149:       if to = @params[:timeout]
150: 
151:         @scheduler.in(to, :tags => 'timeout') do
152: 
153:           # at this point, @job_thread might be set
154: 
155:           @job_thread.raise(Rufus::Scheduler::TimeOutError) \
156:             if @job_thread and @job_thread.alive?
157:         end
158:       end
159:     end
unschedule ()

Unschedules this job.

[show source]
     # File lib/rufus/sc/jobs.rb, line 163
163:     def unschedule
164: 
165:       @scheduler.unschedule(self.job_id)
166:     end