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 17 |
# 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]) @block = block @if = [:if] @thread = .fetch(:thread, @manager.config[:thread]) @timezone = .fetch(:tz, @manager.config[:tz]) @skip_first_run = [:skip_first_run] @last = @skip_first_run ? convert_timezone(Time.now) : nil 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
19 20 21 |
# File 'lib/clockwork/event.rb', line 19 def convert_timezone(t) @timezone ? t.in_time_zone(@timezone) : t end |
#run(t) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/clockwork/event.rb', line 35 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
23 24 25 26 27 28 29 |
# File 'lib/clockwork/event.rb', line 23 def run_now?(t) t = convert_timezone(t) return false unless elapsed_ready?(t) return false unless run_at?(t) return false unless run_if?(t) true end |
#thread? ⇒ Boolean
31 32 33 |
# File 'lib/clockwork/event.rb', line 31 def thread? @thread end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/clockwork/event.rb', line 52 def to_s job.to_s end |