Class: Pwrake::Writer

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/pwrake/worker/writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWriter

Returns a new instance of Writer.



8
9
10
11
12
13
14
# 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

Instance Attribute Details

#outObject

Returns the value of attribute out.



16
17
18
# File 'lib/pwrake/worker/writer.rb', line 16

def out
  @out
end

Instance Method Details

#add_logger(log) ⇒ Object



37
38
39
# File 'lib/pwrake/worker/writer.rb', line 37

def add_logger(log)
  @log = log
end

#dputs(s) ⇒ Object



54
55
56
# File 'lib/pwrake/worker/writer.rb', line 54

def dputs(s)
  puts(s) if $DEBUG
end

#flushObject



47
48
49
50
51
52
# File 'lib/pwrake/worker/writer.rb', line 47

def flush
  begin
    @out.flush
  rescue
  end
end

#heartbeat=(t) ⇒ Object



18
19
20
21
22
23
24
25
# 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_loopObject



27
28
29
30
31
32
33
34
35
# 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) ⇒ Object



41
42
43
44
45
# File 'lib/pwrake/worker/writer.rb', line 41

def puts(s)
  _puts(s)
  @cond_hb = false
  @thread.run
end