Class: Perus::Pinger::Script
- Defined in:
- lib/perus/pinger/commands/script.rb
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
Methods inherited from Command
abstract!, abstract?, #cleanup, #darwin?, description, human_name, inherited, #initialize, metric!, metric?, option, options, #shell, subclasses
Constructor Details
This class inherits a constructor from Perus::Pinger::Command
Instance Method Details
#run ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 49 50 51 52 53 54 55 56 57 |
# File 'lib/perus/pinger/commands/script.rb', line 6 def run actions = [] results = [] late_actions = [] .commands.each do |config| begin command = ::Perus::Pinger.const_get(config['type']) actions << command.new(config['options'], config['id']) rescue => e if config['id'] results[config['id']] = e.inspect else puts 'Error - action does not have an associated id' p config end end end actions.each do |action| begin result = action.run if result.instance_of?(Proc) late_actions << result result = true end results << result rescue => e results << e.inspect end end failed = results.any? {|result| result.is_a?(String)} return results.join(', ') if failed if late_actions.empty? true else Proc.new do late_actions.each do |code| begin code.call rescue => e puts 'Error running late action' puts e.inspect end end end end end |