Class: Invoker::CommandWorker
- Inherits:
-
Object
- Object
- Invoker::CommandWorker
- Defined in:
- lib/invoker/command_worker.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#command_label ⇒ Object
Returns the value of attribute command_label.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#pipe_end ⇒ Object
Returns the value of attribute pipe_end.
Instance Method Summary collapse
-
#initialize(command_label, pipe_end, pid, color) ⇒ CommandWorker
constructor
A new instance of CommandWorker.
-
#receive_data(data) ⇒ Object
Copied verbatim from Eventmachine code.
-
#receive_line(line) ⇒ Object
Print the lines received over the network.
- #send_data(socket, data) ⇒ Object
- #to_h ⇒ Object
- #unbind ⇒ Object
Constructor Details
#initialize(command_label, pipe_end, pid, color) ⇒ CommandWorker
Returns a new instance of CommandWorker.
5 6 7 8 9 10 |
# 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 |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
3 4 5 |
# File 'lib/invoker/command_worker.rb', line 3 def color @color end |
#command_label ⇒ Object
Returns the value of attribute command_label.
3 4 5 |
# File 'lib/invoker/command_worker.rb', line 3 def command_label @command_label end |
#pid ⇒ Object
Returns the value of attribute pid.
3 4 5 |
# File 'lib/invoker/command_worker.rb', line 3 def pid @pid end |
#pipe_end ⇒ Object
Returns the value of attribute pipe_end.
3 4 5 |
# File 'lib/invoker/command_worker.rb', line 3 def pipe_end @pipe_end end |
Instance Method Details
#receive_data(data) ⇒ Object
Copied verbatim from Eventmachine code
13 14 15 16 17 18 19 |
# 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) ⇒ Object
Print the lines received over the network
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
47 48 49 50 51 52 |
# 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 ⇒ Object
43 44 45 |
# File 'lib/invoker/command_worker.rb', line 43 def to_h { command_label: command_label, pid: pid.to_s } end |