Class: Gorgon::GemCommandHandler
- Inherits:
-
Object
- Object
- Gorgon::GemCommandHandler
- Defined in:
- lib/gorgon/gem_command_handler.rb
Instance Method Summary collapse
- #handle(payload, configuration) ⇒ Object
-
#initialize(bunny) ⇒ GemCommandHandler
constructor
A new instance of GemCommandHandler.
Constructor Details
#initialize(bunny) ⇒ GemCommandHandler
Returns a new instance of GemCommandHandler.
9 10 11 |
# File 'lib/gorgon/gem_command_handler.rb', line 9 def initialize bunny @bunny = bunny end |
Instance Method Details
#handle(payload, configuration) ⇒ Object
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 |
# File 'lib/gorgon/gem_command_handler.rb', line 13 def handle payload, configuration reply_exchange_name = payload[:reply_exchange_name] publish_to reply_exchange_name, :type => :running_command gem = configuration[:bin_gem_path] || "gem" cmd = "#{gem} #{payload[:body][:gem_command]} gorgon" pid, stdin, stdout, stderr = Open4::popen4 cmd stdin.close ignore, status = Process.waitpid2 pid exitstatus = status.exitstatus output, errors = [stdout, stderr].map { |p| begin p.read ensure p.close end } if exitstatus == 0 reply = {:type => :command_completed, :command => cmd, :stdout => output, :stderr => errors} publish_to reply_exchange_name, reply @bunny.stop exit # TODO: for now exit until we implement a command to exit listeners else reply = {:type => :command_failed, :command => cmd, :stdout => output, :stderr => errors} publish_to reply_exchange_name, reply end end |