Class: Punctual
- Inherits:
-
Object
- Object
- Punctual
- Defined in:
- lib/punctual.rb
Instance Attribute Summary collapse
-
#jobs ⇒ Object
readonly
Returns the value of attribute jobs.
Instance Method Summary collapse
-
#initialize ⇒ Punctual
constructor
A new instance of Punctual.
-
#schedule(name, cron, &block) ⇒ Object
register new job.
-
#start ⇒ Object
starts the scheduler.
Constructor Details
#initialize ⇒ Punctual
Returns a new instance of Punctual.
6 7 8 9 10 |
# File 'lib/punctual.rb', line 6 def initialize @sleep_time = 1 @clock_initialized = false @jobs = Array.new end |
Instance Attribute Details
#jobs ⇒ Object (readonly)
Returns the value of attribute jobs.
4 5 6 |
# File 'lib/punctual.rb', line 4 def jobs @jobs end |
Instance Method Details
#schedule(name, cron, &block) ⇒ Object
register new job
13 14 15 16 17 |
# File 'lib/punctual.rb', line 13 def schedule(name, cron, &block) job = Job.new(name, cron, block) puts "Scheduling block: #{name}, #{cron}" @jobs.push(job) end |
#start ⇒ Object
starts the scheduler
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/punctual.rb', line 20 def start() t = Thread.new do while true do time = Time.new if (time.sec == 0) @sleep_time = 60 @clock_initialized = true end @jobs.each do |job| if @clock_initialized == true && job.should_execute? job.execute end end sleep @sleep_time end end t.join end |