Class: Clockwork::Event
- Inherits:
-
Object
- Object
- Clockwork::Event
- Defined in:
- lib/clockwork/event.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#job ⇒ Object
Returns the value of attribute job.
-
#last ⇒ Object
Returns the value of attribute last.
Instance Method Summary collapse
- #convert_timezone(t) ⇒ Object
-
#initialize(manager, period, job, block, options = {}) ⇒ Event
constructor
A new instance of Event.
- #run(t) ⇒ Object
- #run_now?(t) ⇒ Boolean
- #thread? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(manager, period, job, block, options = {}) ⇒ Event
Returns a new instance of Event.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/clockwork/event.rb', line 5 def initialize(manager, period, job, block, ={}) validate_if_option([:if]) @manager = manager @period = period @job = job @at = At.parse([:at]) @last = nil @block = block @if = [:if] @thread = .fetch(:thread, @manager.config[:thread]) @timezone = .fetch(:tz, @manager.config[:tz]) end |
Instance Attribute Details
#job ⇒ Object
Returns the value of attribute job.
3 4 5 |
# File 'lib/clockwork/event.rb', line 3 def job @job end |
#last ⇒ Object
Returns the value of attribute last.
3 4 5 |
# File 'lib/clockwork/event.rb', line 3 def last @last end |
Instance Method Details
#convert_timezone(t) ⇒ Object
18 19 20 |
# File 'lib/clockwork/event.rb', line 18 def convert_timezone(t) @timezone ? t.in_time_zone(@timezone) : t end |
#run(t) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/clockwork/event.rb', line 31 def run(t) @manager.log "Triggering '#{self}'" @last = convert_timezone(t) if thread? if @manager.thread_available? t = Thread.new do execute end t['creator'] = @manager else @manager.log_error "Threads exhausted; skipping #{self}" end else execute end end |
#run_now?(t) ⇒ Boolean
22 23 24 25 |
# File 'lib/clockwork/event.rb', line 22 def run_now?(t) t = convert_timezone(t) elapsed_ready(t) and (@at.nil? or @at.ready?(t)) and (@if.nil? or @if.call(t)) end |
#thread? ⇒ Boolean
27 28 29 |
# File 'lib/clockwork/event.rb', line 27 def thread? @thread end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/clockwork/event.rb', line 48 def to_s job.to_s end |