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.
-
#dancer ⇒ Object
Returns the value of attribute dancer.
-
#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(dancer, interval, &block) ⇒ Task
constructor
A new instance of Task.
- #run ⇒ Object
- #time_to_run? ⇒ Boolean
Constructor Details
#initialize(dancer, interval, &block) ⇒ Task
Returns a new instance of Task.
4 5 6 7 8 9 10 11 12 |
# File 'lib/loop_dance/task.rb', line 4 def initialize( dancer, interval, &block ) run_count=0 self.dancer = dancer self.interval = interval self.block = block # Run tasks when start dancer # 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 |
#dancer ⇒ Object
Returns the value of attribute dancer.
2 3 4 |
# File 'lib/loop_dance/task.rb', line 2 def dancer @dancer 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
18 19 20 21 22 23 24 25 |
# File 'lib/loop_dance/task.rb', line 18 def run block.call rescue Exception => e puts "Uncaught exception bubbled up: \n#{e.class}: #{e.}\n\t#{e.backtrace.join("\n\t")} " dancer.send(:stop_dancer) ensure self.last_run_at = Time.now end |
#time_to_run? ⇒ Boolean
14 15 16 |
# File 'lib/loop_dance/task.rb', line 14 def time_to_run? !last_run_at || last_run_at + interval <= Time.now end |