Parent

Rufus::Scheduler::Job

The base class for all types of jobs.

Attributes

scheduler[RW]

A reference to the scheduler owning this job

t[R]

The initial, raw, scheduling info (at / in / every / cron)

last_job_thread[R]

Returns the thread instance of the last triggered job. May be null (especially before the first trigger).

params[R]

The job parameters (passed via the schedule method)

block[R]

The block to call when triggering

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 ?)) )

job_id[R]

The identifier for this job.

running[RW]

Public Class Methods

new(scheduler, t, params, &block) click to toggle source

Instantiating the job.

    # 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:       @running = false
82:       @allow_overlapping = true
83:       if !params[:allow_overlapping].nil?
84:         @allow_overlapping = params[:allow_overlapping]
85:       end
86: 
87:       raise ArgumentError.new(
88:         'no block or :schedulable passed, nothing to schedule'
89:       ) unless @block
90: 
91:       @params[:tags] = Array(@params[:tags])
92: 
93:       @job_id = params[:job_id] || "#{self.class.name}_#{self.object_id.to_s}"
94: 
95:       determine_at
96:     end

Public Instance Methods

schedule_info() click to toggle source

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

     # File lib/rufus/sc/jobs.rb, line 116
116:     def schedule_info
117: 
118:       @t
119:     end
tags() click to toggle source

Returns the list of tags attached to the job.

     # File lib/rufus/sc/jobs.rb, line 100
100:     def tags
101: 
102:       @params[:tags]
103:     end
tags=(tags) click to toggle source

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

     # File lib/rufus/sc/jobs.rb, line 108
108:     def tags=(tags)
109: 
110:       @params[:tags] = Array(tags)
111:     end
trigger(t=Time.now) click to toggle source

Triggers the job.

     # File lib/rufus/sc/jobs.rb, line 123
123:     def trigger(t=Time.now)
124: 
125:       @last = t
126:       job_thread = nil
127:       to_job = nil
128: 
129:       return if @running && !@allow_overlapping
130: 
131:       @running = true
132:       @scheduler.send(:trigger_job, @params[:blocking]) do
133:         #
134:         # Note that #trigger_job is protected, hence the #send
135:         # (Only jobs know about this method of the scheduler)
136: 
137:         job_thread = Thread.current
138:         job_thread[
139:           "rufus_scheduler__trigger_thread__#{@scheduler.object_id}"
140:         ] = true
141:         @last_job_thread = job_thread
142: 
143:         begin
144: 
145:           trigger_block
146: 
147:           job_thread = nil
148:           to_job.unschedule if to_job
149: 
150:           @running = false
151: 
152:         rescue Exception => e
153: 
154:           @scheduler.handle_exception(self, e)
155:         end
156:       end
157: 
158:       # note that add_job and add_cron_job ensured that :blocking is
159:       # not used along :timeout
160: 
161:       if to = @params[:timeout]
162: 
163:         to_job = @scheduler.in(to, :parent => self, :tags => 'timeout') do
164: 
165:           # at this point, @job_thread might be set
166: 
167:           if job_thread && job_thread.alive?
168:             job_thread.raise(Rufus::Scheduler::TimeOutError)
169:           end
170:         end
171:       end
172: 
173:     end
trigger_block() click to toggle source

Simply encapsulating the block#/trigger operation, for easy override.

     # File lib/rufus/sc/jobs.rb, line 178
178:     def trigger_block
179: 
180:       @block.respond_to?(:call) ?
181:         @block.call(self) : @block.trigger(@params.merge(:job => self))
182:     end
unschedule() click to toggle source

Unschedules this job.

     # File lib/rufus/sc/jobs.rb, line 186
186:     def unschedule
187: 
188:       @scheduler.unschedule(self.job_id)
189:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.