Class: LoopDance::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/loop_dance/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#blockObject

Returns the value of attribute block.



2
3
4
# File 'lib/loop_dance/task.rb', line 2

def block
  @block
end

#dancerObject

Returns the value of attribute dancer.



2
3
4
# File 'lib/loop_dance/task.rb', line 2

def dancer
  @dancer
end

#intervalObject

Returns the value of attribute interval.



2
3
4
# File 'lib/loop_dance/task.rb', line 2

def interval
  @interval
end

#last_run_atObject

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

#runObject



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.message}\n\t#{e.backtrace.join("\n\t")} "
  dancer.send(:stop_dancer)
ensure
  self.last_run_at = Time.now
end

#time_to_run?Boolean

Returns:

  • (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