Class: LoopDance::Task
- Inherits:
-
Object
- Object
- LoopDance::Task
- Defined in:
- lib/loop_dance/task.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#last_run_at ⇒ Object
Returns the value of attribute last_run_at.
Instance Method Summary collapse
-
#initialize(interval, &block) ⇒ Task
constructor
A new instance of Task.
- #run ⇒ Object
- #time_to_run? ⇒ Boolean
Constructor Details
#initialize(interval, &block) ⇒ Task
Returns a new instance of Task.
4 5 6 7 8 9 |
# File 'lib/loop_dance/task.rb', line 4 def initialize( interval, &block ) run_count=0 self.interval = interval self.block = block self.last_run_at = Time.now end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
2 3 4 |
# File 'lib/loop_dance/task.rb', line 2 def block @block end |
#interval ⇒ Object
Returns the value of attribute interval.
2 3 4 |
# File 'lib/loop_dance/task.rb', line 2 def interval @interval end |
#last_run_at ⇒ Object
Returns the value of attribute last_run_at.
2 3 4 |
# File 'lib/loop_dance/task.rb', line 2 def last_run_at @last_run_at end |
Instance Method Details
#run ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/loop_dance/task.rb', line 15 def run block.call rescue Exception => e puts "Uncaught exception bubbled up: \n#{e.class}: #{e.}\n\t#{e.backtrace.join("\n\t")} " ensure self.last_run_at = Time.now end |
#time_to_run? ⇒ Boolean
11 12 13 |
# File 'lib/loop_dance/task.rb', line 11 def time_to_run? !last_run_at || last_run_at + interval <= Time.now end |