Class: Polyrun::WorkerOutput::WorkerForwarder

Inherits:
Object
  • Object
show all
Defined in:
lib/polyrun/worker_output_forwarders.rb

Instance Method Summary collapse

Constructor Details

#initialize(shard:, pid:, log_path:, prefix_live:) ⇒ WorkerForwarder

Returns a new instance of WorkerForwarder.



65
66
67
68
69
70
71
72
# File 'lib/polyrun/worker_output_forwarders.rb', line 65

def initialize(shard:, pid:, log_path:, prefix_live:)
  @shard = shard
  @pid = pid
  @log_io = File.open(log_path, "wb")
  @stdout = LineForwarder.new(shard: shard, pid: pid, log_io: @log_io, prefix_live: prefix_live, tty_io: Polyrun::Log.stdout)
  @stderr = LineForwarder.new(shard: shard, pid: pid, log_io: @log_io, prefix_live: prefix_live, tty_io: Polyrun::Log.stderr)
  @write_mutex = Mutex.new
end

Instance Method Details

#closeObject



83
84
85
86
87
# File 'lib/polyrun/worker_output_forwarders.rb', line 83

def close
  @stdout.flush
  @stderr.flush
  @log_io.close
end

#consume(stream, chunk) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/polyrun/worker_output_forwarders.rb', line 74

def consume(stream, chunk)
  @write_mutex.synchronize do
    case stream
    when :stdout then @stdout.consume(chunk)
    when :stderr then @stderr.consume(chunk)
    end
  end
end