class Invoker::CommandWorker
Attributes
color[RW]
command_label[RW]
pid[RW]
pipe_end[RW]
Public Class Methods
new(command_label, pipe_end, pid, color)
click to toggle source
# File lib/invoker/command_worker.rb, line 5 def initialize(command_label, pipe_end, pid, color) @command_label = command_label @pipe_end = pipe_end @pid = pid @color = color end
Public Instance Methods
receive_data(data)
click to toggle source
Copied verbatim from Eventmachine code
# File lib/invoker/command_worker.rb, line 13 def receive_data data (@buf ||= '') << data while @buf.slice!(/(.*?)\r?\n/) receive_line($1) end end
receive_line(line)
click to toggle source
Print the lines received over the network
# File lib/invoker/command_worker.rb, line 26 def receive_line(line) tail_watchers = Invoker.tail_watchers[@command_label] color_line = "#{@command_label.colorize(color)} : #{line}" plain_line = "#{@command_label} : #{line}" if Invoker.nocolors? Invoker::Logger.puts plain_line else Invoker::Logger.puts color_line end if tail_watchers && !tail_watchers.empty? json_encoded_tail_response = tail_response(color_line) if json_encoded_tail_response tail_watchers.each { |tail_socket| send_data(tail_socket, json_encoded_tail_response) } end end end
send_data(socket, data)
click to toggle source
# File lib/invoker/command_worker.rb, line 47 def send_data(socket, data) socket.write(data) rescue Invoker::Logger.puts "Removing #{@command_label} watcher #{socket} from list" Invoker.tail_watchers.remove(@command_label, socket) end
to_h()
click to toggle source
# File lib/invoker/command_worker.rb, line 43 def to_h { command_label: command_label, pid: pid.to_s } end
unbind()
click to toggle source
# File lib/invoker/command_worker.rb, line 21 def unbind Invoker::Logger.print(".") end
Private Instance Methods
tail_response(line)
click to toggle source
Encode current line as json and send the response.
# File lib/invoker/command_worker.rb, line 57 def tail_response(line) tail_response = Invoker::IPC::Message::TailResponse.new(tail_line: line) tail_response.encoded_message rescue nil end