Module: Trabox::Command::Relay

Defined in:
lib/trabox/commands/relay.rb,
lib/trabox/commands/relay/configuration.rb,
lib/trabox/commands/relay/argument_parser.rb

Defined Under Namespace

Classes: ArgumentParser, Configuration

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.activeObject Also known as: active?

Returns the value of attribute active.



7
8
9
# File 'lib/trabox/commands/relay/configuration.rb', line 7

def active
  @active
end

Class Method Details

.configObject



16
17
18
# File 'lib/trabox/commands/relay/configuration.rb', line 16

def config
  @config ||= Configuration.new
end

.config_activateObject



20
21
22
# File 'lib/trabox/commands/relay/configuration.rb', line 20

def config_activate
  @active = true
end

.configure {|config| ... } ⇒ Object

Yields:



10
11
12
13
14
# File 'lib/trabox/commands/relay/configuration.rb', line 10

def configure
  return unless active?

  yield config
end

.performObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/trabox/commands/relay.rb', line 22

def self.perform
  prepare

  relayer = Trabox::Relay::Relayer.new(
    config.publisher,
    limit: config.limit,
    lock: config.lock
  )

  interval = config.interval

  loop do
    begin
      relayer.perform

      Metric.service_check('relay.service.check', Metric::SERVICE_OK)
    rescue StandardError => e
      Rails.logger.error e

      ActiveRecord::Base.clear_all_connections!

      Metric.service_check('relay.service.check', Metric::SERVICE_CRITICAL)
    end

    sleep interval
  end
end

.prepareObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/trabox/commands/relay.rb', line 9

def prepare
  config_activate

  Runner.load_runner

  ArgumentParser.parse!

  config.check

  Rails.logger.level = config.log_level
end