Class: InstanceAgent::Runner::Child
- Inherits:
-
ProcessManager::Daemon::Child
- Object
- ProcessManager::Daemon::Child
- InstanceAgent::Runner::Child
- Defined in:
- lib/instance_agent/runner/child.rb
Instance Attribute Summary collapse
-
#runner ⇒ Object
Returns the value of attribute runner.
Instance Method Summary collapse
- #description ⇒ Object
- #load_plugins(plugins) ⇒ Object
- #prepare_run ⇒ Object
- #run ⇒ Object
- #validate_index ⇒ Object
- #with_error_handling ⇒ Object
Instance Attribute Details
#runner ⇒ Object
Returns the value of attribute runner.
8 9 10 |
# File 'lib/instance_agent/runner/child.rb', line 8 def runner @runner end |
Instance Method Details
#description ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/instance_agent/runner/child.rb', line 42 def description if runner "#{runner.description} of master #{master_pid.inspect}" else 'booting child' end end |
#load_plugins(plugins) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/instance_agent/runner/child.rb', line 10 def load_plugins(plugins) ProcessManager::Log.debug("Registering Plugins: #{plugins.inspect}.") plugins.each do |plugin| plugin_dir = File.("../plugins/#{plugin}/register_plugin", File.dirname(__FILE__)) ProcessManager::Log.debug("Loading plugin #{plugin} from #{plugin_dir}") begin require plugin_dir rescue LoadError => e ProcessManager::Log.error("Plugin #{plugin} could not be loaded: #{e.message}.") raise end end registered_plugins = InstanceAgent::Agent::Base.plugins ProcessManager::Log.debug("Registered Plugins: #{registered_plugins.inspect}.") Hash[registered_plugins.map.with_index { |value, index| [index, value] }] end |
#prepare_run ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/instance_agent/runner/child.rb', line 27 def prepare_run @plugins ||= load_plugins(ProcessManager::Config.config[:plugins] || ["codedeploy"]) validate_index with_error_handling do @runner = @plugins[index].runner ProcessManager.set_program_name(description) end end |
#run ⇒ Object
36 37 38 39 40 |
# File 'lib/instance_agent/runner/child.rb', line 36 def run with_error_handling do runner.run end end |
#validate_index ⇒ Object
50 51 52 |
# File 'lib/instance_agent/runner/child.rb', line 50 def validate_index raise ArgumentError, "Invalid index #{index.inspect}" unless @plugins.keys.include?(index) end |
#with_error_handling ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/instance_agent/runner/child.rb', line 54 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..to_s.match(/throttle/i) || e..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 |