Class: Unicron::Schedule
- Inherits:
-
Object
- Object
- Unicron::Schedule
- Defined in:
- lib/unicron/schedule.rb
Overview
Schedule manages a JobQueue which contains Job instances, and a thread which pops and executes them. For simplicity’s sake, the Unicron module manages a default Schedule, but you can create and manage your own if necessary. Each uses its own JobQueue and thread, so they will not interfere with each other.
Instance Method Summary collapse
-
#<<(job) ⇒ Object
Add a Job to the Schedule’s JobQueue.
-
#initialize ⇒ Schedule
constructor
Create a new, empty Schedule.
-
#schedule(options = {}, &block) ⇒ Object
Create a new Job and add it to the Schedule.
Constructor Details
#initialize ⇒ Schedule
Create a new, empty Schedule. The Schedule’s thread is started and blocks immediately, waiting for a Job to be added.
21 22 23 24 |
# File 'lib/unicron/schedule.rb', line 21 def initialize @queue = Unicron::JobQueue.new @thread = Thread.new &method(:run) end |
Instance Method Details
#<<(job) ⇒ Object
Add a Job to the Schedule’s JobQueue.
12 13 14 15 |
# File 'lib/unicron/schedule.rb', line 12 def << job @queue << job self end |
#schedule(options = {}, &block) ⇒ Object
Create a new Job and add it to the Schedule. See Job::new for available options.
30 31 32 33 34 |
# File 'lib/unicron/schedule.rb', line 30 def schedule ={}, &block job = Unicron::Job.new , &block self << job job end |