Class: Ambo::Runner

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/ambo/runner.rb

Overview

This class is responsible for running and managing all bots. The #wait_until_exit! method is called by the Loader class.

This class will also setup signal handlers for SIGINT and SIGTERM. Both signals are trapped in order to gracefully shutdown the bots.

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.


12
13
14
15
16
17
18
# File 'lib/ambo/runner.rb', line 12

def initialize
  @deliveries = []
  @tasks = []

  @store = Store.new
  @outbound_pool = Ambo::Task.create_pool
end

Instance Method Details

#<<(ctx) ⇒ Object

Parameters:


21
22
23
24
25
26
27
28
# File 'lib/ambo/runner.rb', line 21

def <<(ctx)
  state = @store.load_or_create(ctx)

  create_periodic_task(ctx, state) if ctx.periodic?
  create_twitter_delivery(ctx) if ctx.twitter?

  self
end

#wait_until_exit!Object

Called by the main thread; will block until shutdown


31
32
33
34
35
36
37
# File 'lib/ambo/runner.rb', line 31

def wait_until_exit!
  trap_signals!

  until @outbound_pool.wait_for_termination(60)
    debug_log Ambo.random_beep_boops
  end
end