Class: Courgette::Executor
- Inherits:
-
Object
- Object
- Courgette::Executor
- Defined in:
- lib/courgette/executor.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #fetch_and_update(device) ⇒ Object
-
#initialize(client, executors, logger) ⇒ Executor
constructor
A new instance of Executor.
- #launch!(filter) ⇒ Object
Constructor Details
#initialize(client, executors, logger) ⇒ Executor
Returns a new instance of Executor.
5 6 7 8 9 |
# File 'lib/courgette/executor.rb', line 5 def initialize(client, executors, logger) @client = client @executors = executors @logger = logger end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/courgette/executor.rb', line 3 def client @client end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
3 4 5 |
# File 'lib/courgette/executor.rb', line 3 def logger @logger end |
Instance Method Details
#fetch_and_update(device) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/courgette/executor.rb', line 21 def fetch_and_update(device) begin status = client.update_device(device.ip, device.fetch) logger.info "#{device} #{status}" rescue Timeout::Error logger.info "#{device} is unreachable (timeout)" rescue Net::SSH::Disconnect logger.info "#{device} is unreachable (disconnect)" rescue Net::SSH::AuthenticationFailed logger.info "#{device} credentials are incorrect" rescue Errno::ECONNREFUSED logger.info "#{device} is unreachable (connection refused)" rescue Net::SSH::Exception => e logger.info "#{device} ssh error (#{e.})" rescue => e logger.info "#{device} fatal error (#{e.class} - #{e.})" end end |
#launch!(filter) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/courgette/executor.rb', line 11 def launch!(filter) Parallel.each(client.devices.select { |device| filter.call(device) }, in_threads: @executors) do |device| begin Timeout::timeout(240) { fetch_and_update(device) } rescue logger.info "#{device} execution too long (timeout)" end end end |