Class: Rufus::TrackingScheduler
- Inherits:
-
Object
- Object
- Rufus::TrackingScheduler
show all
- Defined in:
- lib/rufus-runner/tracking_scheduler.rb,
lib/rufus-runner/tracking_scheduler.rb
Overview
Wraps Rufus’s scheduler class with signal handling, cancellation of jobs, and logging.
Defined Under Namespace
Classes: ForkingJobRunner, JobRunner, ThreadingJobRunner
Constant Summary
collapse
- GRACE_DELAY =
wait that long for jobs to complete before quitting (seconds)
10
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of TrackingScheduler.
17
18
19
20
21
|
# File 'lib/rufus-runner/tracking_scheduler.rb', line 17
def initialize(options = {})
@options = DefaultOptions.merge(options)
@scheduler = Rufus::Scheduler.new
log('scheduler started')
end
|
Class Method Details
.start(options = {}) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/rufus-runner/tracking_scheduler.rb', line 51
def self.start(options = {})
EM.run do
scheduler = new(options)
scheduler.send :setup_traps
yield scheduler
end
end
|
Instance Method Details
#log(string) ⇒ Object
68
69
70
71
|
# File 'lib/rufus-runner/tracking_scheduler.rb', line 68
def log(string)
$stdout.write "[#{$PROGRAM_NAME} #{format_time Time.now}] #{string}\n"
$stdout.flush
end
|
#run(options = {}, &block) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/rufus-runner/tracking_scheduler.rb', line 23
def run(options={}, &block)
return unless rails_environment_matches?(options.delete(:environments))
options = @options.merge(options)
name = options.delete(:name) || 'noname'
case options.delete(:fork) || :thread
when :thread
job_runner_class = ThreadingJobRunner
when :process
job_runner_class = ForkingJobRunner
else
fail ArgumentError.new("option :fork needs to be either :thread or :process")
end
schedule(options) do |job|
job_runner = job_runner_class.new(
:name => name,
:job => job,
:block => block,
:scheduler => self
)
job_runner.run
end
log("scheduled '#{name}'")
nil
end
|
#shutting_down! ⇒ Object
59
60
61
|
# File 'lib/rufus-runner/tracking_scheduler.rb', line 59
def shutting_down!
@shutting_down = true
end
|
#shutting_down? ⇒ Boolean
63
64
65
|
# File 'lib/rufus-runner/tracking_scheduler.rb', line 63
def shutting_down?
!!@shutting_down
end
|