Class: ConsadoleAggregator::Live::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/consadole_aggregator/live.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(starting_time) ⇒ Runner

Returns a new instance of Runner.



13
14
15
16
17
18
# File 'lib/consadole_aggregator/live.rb', line 13

def initialize starting_time
  @starting_time = starting_time
  @length_of_a_game = 120 * 60
  @interval = 60
  @daemonize = true
end

Instance Attribute Details

#daemonize=(value) ⇒ Object (writeonly)

Sets the attribute daemonize

Parameters:

  • value

    the value to set the attribute daemonize to.



11
12
13
# File 'lib/consadole_aggregator/live.rb', line 11

def daemonize=(value)
  @daemonize = value
end

#interval=(value) ⇒ Object (writeonly)

Sets the attribute interval

Parameters:

  • value

    the value to set the attribute interval to.



11
12
13
# File 'lib/consadole_aggregator/live.rb', line 11

def interval=(value)
  @interval = value
end

#length_of_a_game=(value) ⇒ Object (writeonly)

Sets the attribute length_of_a_game

Parameters:

  • value

    the value to set the attribute length_of_a_game to.



11
12
13
# File 'lib/consadole_aggregator/live.rb', line 11

def length_of_a_game=(value)
  @length_of_a_game = value
end

Instance Method Details

#run(&block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/consadole_aggregator/live.rb', line 20

def run &block
  Process.daemon if @daemonize

  starting = @starting_time - Time.now
  ending = starting + @length_of_a_game
  live = Live.new

  EM.run do
    EM.add_timer(starting) do
      EM.next_tick do
        EM.add_periodic_timer(@interval) do
          live.update &block
        end
      end
    end

    EM.add_timer(ending) do
      EM.stop
    end
  end
end