Sha256: 6710c521319b9234b73d3c32f18f0fb3196d1576cf7873719224be18bd3d53f6
Contents?: true
Size: 1.48 KB
Versions: 8
Compression:
Stored size: 1.48 KB
Contents
module Workers class System extend Resque::Plugins::Result @queue = :system_queue # # Resque worker method. # def self.perform(meta_id, cmd, remote, ssh_host, ssh_user, ssh_options = {}, stdout = false) unless ssh_options.empty? # Convert each key in ssh_options to a symbol. ssh_options = ssh_options.inject({}) do |memo, (k, v)| memo[k.to_sym] = v memo end end exit_status = 1 out = "" if remote # Execute command on remote machine. Net::SSH.start(ssh_host, ssh_user, ssh_options) do |ssh| ssh.open_channel do |ch| ch.exec(cmd) do |ch, success| if success # Capture STDOUT from ch.exec() if stdout ch.on_data do |ch, data| out = data end end # Read the exit status of the remote process. ch.on_request("exit-status") do |ch, data| exit_status = data.read_long end else Rails.logger.warn "Channel Net::SSH exec() failed. :'(" end end end ssh.loop end else out = `#{cmd}` exit_status = $?.exitstatus end if exit_status > 0 raise "Worker failed :'(. See quorum/log/quorum.log for more information." end out if stdout end end end
Version data entries
8 entries across 8 versions & 1 rubygems