Class: Clockwork::Event
- Inherits:
-
Object
- Object
- Clockwork::Event
- Defined in:
- lib/clockwork.rb
Instance Attribute Summary collapse
-
#job ⇒ Object
Returns the value of attribute job.
-
#last ⇒ Object
Returns the value of attribute last.
Instance Method Summary collapse
- #exception_message(e) ⇒ Object
-
#initialize(period, job, block, options = {}) ⇒ Event
constructor
A new instance of Event.
- #log_error(e) ⇒ Object
- #run(t) ⇒ Object
- #time?(t) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#job ⇒ Object
Returns the value of attribute job.
53 54 55 |
# File 'lib/clockwork.rb', line 53 def job @job end |
#last ⇒ Object
Returns the value of attribute last.
53 54 55 |
# File 'lib/clockwork.rb', line 53 def last @last end |
Instance Method Details
#exception_message(e) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/clockwork.rb', line 83 def (e) msg = [ "Exception #{e.class} -> #{e.}" ] base = File.(Dir.pwd) + '/' e.backtrace.each do |t| msg << " #{File.(t).gsub(/#{base}/, '')}" end msg.join("\n") end |
#log_error(e) ⇒ Object
79 80 81 |
# File 'lib/clockwork.rb', line 79 def log_error(e) STDERR.puts (e) end |
#run(t) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/clockwork.rb', line 72 def run(t) @last = t @block.call(@job) rescue => e log_error(e) end |
#time?(t) ⇒ Boolean
67 68 69 70 |
# File 'lib/clockwork.rb', line 67 def time?(t) ellapsed_ready = (@last.nil? or (t - @last).to_i >= @period) ellapsed_ready and (@at.nil? or @at.ready?(t)) end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/clockwork.rb', line 63 def to_s @job end |