Object
The base class for all types of jobs.
Returns the thread instance of the last triggered job. May be null (especially before the first trigger).
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
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
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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.