Class: Warren::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, Helpers::StateMachine
Defined in:
lib/warren/client.rb

Overview

Establishes message queue consumers Fox according to the configuration. Usually generated via the App::Consumer and triggered via the command line ‘warren consumer start`

Constant Summary collapse

SECONDS_TO_SLEEP =

The interrupt updates the client state to ‘stopping’ and the control loop handles the actual shutdown. This is as there are limitations on what may take place during an interrupt. This constant controls the frequency at while the control loop polls its state.

3

Instance Method Summary collapse

Methods included from Helpers::StateMachine

state, states

Constructor Details

#initialize(config, consumers: nil, adaptor: Warren::FrameworkAdaptor::RailsAdaptor.new) ⇒ Client

Build a new client object based on the configuration in ‘config` and the requested consumers in `consumers`. If `consumers` is nil, all consumers will be spawned. Consumers are spawned on calling #run not at initialization

Parameters:

  • config (Warren::Config::Consumers)

    A consumer configuration object

  • consumers (Array<String>) (defaults to: nil)

    The names of the consumers to spawn, or nil to spawn them all



31
32
33
34
35
# File 'lib/warren/client.rb', line 31

def initialize(config, consumers: nil, adaptor: Warren::FrameworkAdaptor::RailsAdaptor.new)
  @config = config
  @consumers = consumers || @config.all_consumers
  @adaptor = adaptor
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/warren/client.rb', line 54

def alive?
  !stopped?
end

#runObject



37
38
39
40
41
42
43
44
45
# File 'lib/warren/client.rb', line 37

def run
  starting!
  @adaptor.load_application
  connect_to_rabbit_mq
  trap_signals
  foxes.each(&:run!)
  started!
  control_loop while alive?
end

#stop!Object



47
48
49
50
51
52
# File 'lib/warren/client.rb', line 47

def stop!
  stopping!
  # This method is called from within an interrupt, where the logger
  # is unavailable
  $stdout.puts 'Stopping consumers'
end