class Pwrake::Writer
Attributes
out[RW]
Public Class Methods
new()
click to toggle source
# File lib/pwrake/worker/writer.rb, line 8 def initialize @out = $stderr @mutex = Mutex.new @cond_hb = true @heartbeat = nil @thread = Thread.new{ heartbeat_loop } end
Public Instance Methods
add_logger(log)
click to toggle source
# File lib/pwrake/worker/writer.rb, line 37 def add_logger(log) @log = log end
dputs(s)
click to toggle source
# File lib/pwrake/worker/writer.rb, line 54 def dputs(s) puts(s) if $DEBUG end
flush()
click to toggle source
# File lib/pwrake/worker/writer.rb, line 47 def flush begin @out.flush rescue end end
heartbeat=(t)
click to toggle source
# File lib/pwrake/worker/writer.rb, line 18 def heartbeat=(t) if t t = t.to_i t = 15 if t < 15 end @heartbeat = t @thread.run end
heartbeat_loop()
click to toggle source
# File lib/pwrake/worker/writer.rb, line 27 def heartbeat_loop loop do @heartbeat ? sleep(@heartbeat) : sleep if @cond_hb _puts "heartbeat" end @cond_hb = true end end
puts(s)
click to toggle source
# File lib/pwrake/worker/writer.rb, line 41 def puts(s) _puts(s) @cond_hb = false @thread.run end
Private Instance Methods
_puts(s)
click to toggle source
# File lib/pwrake/worker/writer.rb, line 59 def _puts(s) begin @mutex.synchronize do @out.print s+"\n" end @out.flush rescue Errno::EPIPE => e @log.info "<#{e.inspect}" if @log end @log.info "<#{s}" if @log end