Class: InstanceAgent::Runner::Child

Inherits:
ProcessManager::Daemon::Child
  • Object
show all
Defined in:
lib/instance_agent/runner/child.rb

Constant Summary collapse

AGENTS =
{
  0 => InstanceAgent::CodeDeployPlugin::CommandPoller
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#runnerObject

Returns the value of attribute runner.



11
12
13
# File 'lib/instance_agent/runner/child.rb', line 11

def runner
  @runner
end

Instance Method Details

#descriptionObject



27
28
29
30
31
32
33
# File 'lib/instance_agent/runner/child.rb', line 27

def description
  if runner
    "#{runner.description} of master #{master_pid.inspect}"
  else
    'booting child'
  end
end

#prepare_runObject



13
14
15
16
17
18
19
# File 'lib/instance_agent/runner/child.rb', line 13

def prepare_run
  validate_index
  with_error_handling do
    @runner = AGENTS[index].runner
    ProcessManager.set_program_name(description)
  end
end

#runObject



21
22
23
24
25
# File 'lib/instance_agent/runner/child.rb', line 21

def run
  with_error_handling do
    runner.run
  end
end

#validate_indexObject

Raises:

  • (ArgumentError)


35
36
37
# File 'lib/instance_agent/runner/child.rb', line 35

def validate_index
  raise ArgumentError, "Invalid index #{index.inspect}: only 0-2 possible" unless AGENTS.keys.include?(index)
end

#with_error_handlingObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/instance_agent/runner/child.rb', line 39

def with_error_handling
  yield
rescue SocketError => e
  ProcessManager::Log.info "#{description}: failed to run as the connection failed! #{e.class} - #{e.message} - #{e.backtrace.join("\n")}"
  sleep ProcessManager::Config.config[:wait_after_connection_problem]
  exit 1
rescue Exception => e
  if (e.message.to_s.match(/throttle/i) || e.message.to_s.match(/rateexceeded/i) rescue false)
    ProcessManager::Log.error "#{description}: ran into throttling - waiting for #{ProcessManager::Config.config[:wait_after_throttle_error]}s until retrying"
    sleep ProcessManager::Config.config[:wait_after_throttle_error]
  else
    ProcessManager::Log.error "#{description}: error during start or run: #{e.class} - #{e.message} - #{e.backtrace.join("\n")}"
  end
  exit 1
end