Module: Secondhand
- Extended by:
- Secondhand, Scheduler
- Included in:
- Secondhand
- Defined in:
- lib/secondhand.rb,
lib/secondhand/job.rb,
lib/secondhand/jobs.rb,
lib/secondhand/logging.rb,
lib/secondhand/trigger.rb,
lib/secondhand/version.rb,
lib/secondhand/scheduler.rb
Defined Under Namespace
Modules: Job, Jobs, Logger, Scheduler
Classes: NoSchedulerError, Trigger
Constant Summary
collapse
- DEFAULT_GROUP =
"SECONDHAND"
- DEFAULT_THREAD_COUNT =
5
- VERSION =
"0.1.0"
Instance Method Summary
collapse
Instance Method Details
#initialize_scheduler(threads = nil) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/secondhand.rb', line 55
def initialize_scheduler(threads = nil)
@thread_count = threads if threads
System.set_property("org.quartz.threadPool.threadCount", @thread_count.to_s)
System.set_property("org.quartz.scheduler.skipUpdateCheck", "true")
@scheduler = StdSchedulerFactory.default_scheduler
@scheduler.job_factory = Job::Factory.instance
end
|
#job_names ⇒ Object
85
86
87
|
# File 'lib/secondhand.rb', line 85
def job_names
Jobs.names
end
|
#jobs ⇒ Object
81
82
83
|
# File 'lib/secondhand.rb', line 81
def jobs
Jobs
end
|
#reset_thread_count ⇒ Object
36
37
38
|
# File 'lib/secondhand.rb', line 36
def reset_thread_count
@thread_count = DEFAULT_THREAD_COUNT
end
|
#schedule(job, opts = {}, &block) ⇒ Object
67
68
69
70
|
# File 'lib/secondhand.rb', line 67
def schedule(job, opts={}, &block)
name = job.to_s
scheduler.schedule_job(Job.create(name, block ? block : job), Trigger.create(name, opts))
end
|
#scheduler ⇒ Object
Raise an error if the scheduler isn’t ready - with Quartz we have an order of operations to follow. This also lets us pass the threads in with .start
76
77
78
79
|
# File 'lib/secondhand.rb', line 76
def scheduler
raise NoSchedulerError, "Scheduler isn't initialized. Call Secondhand.start before scheduling jobs." unless @scheduler
@scheduler
end
|
#start(threads = nil) ⇒ Object
Also known as:
run
49
50
51
52
|
# File 'lib/secondhand.rb', line 49
def start(threads = nil)
initialize_scheduler(threads)
scheduler.start
end
|
#thread_count ⇒ Object
44
45
46
47
|
# File 'lib/secondhand.rb', line 44
def thread_count
reset_thread_count unless @thread_count
@thread_count
end
|
#thread_count=(threads) ⇒ Object
40
41
42
|
# File 'lib/secondhand.rb', line 40
def thread_count=(threads)
@thread_count = threads
end
|