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



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 = 120
  @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



34
35
36
# File 'lib/pwrake/worker/writer.rb', line 34

def add_logger(log)
  @log = log
end

#dputs(s) ⇒ Object



51
52
53
# File 'lib/pwrake/worker/writer.rb', line 51

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

#flushObject



44
45
46
47
48
49
# File 'lib/pwrake/worker/writer.rb', line 44

def flush
  begin
    @out.flush
  rescue
  end
end

#heartbeat=(t) ⇒ Object



18
19
20
21
# File 'lib/pwrake/worker/writer.rb', line 18

def heartbeat=(t)
  @heartbeat = t.to_i
  @thread.run
end

#heartbeat_loopObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/pwrake/worker/writer.rb', line 23

def heartbeat_loop
  sleep
  loop do
    sleep(@heartbeat)
    if @cond_hb
      _puts "heartbeat"
    end
    @cond_hb = true
  end
end

#puts(s) ⇒ Object



38
39
40
41
42
# File 'lib/pwrake/worker/writer.rb', line 38

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