Class: Tenderloin::Busy
- Inherits:
-
Object
show all
- Extended by:
- Util
- Defined in:
- lib/tenderloin/busy.rb
Constant Summary
collapse
- @@busy =
false
- @@mutex =
Mutex.new
- @@trap_thread =
nil
Class Method Summary
collapse
Methods included from Util
error_and_exit, included, logger, wrap_output
Class Method Details
.busy(&block) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/tenderloin/busy.rb', line 26
def busy(&block)
@@mutex.synchronize do
begin
Signal.trap("INT") { wait_for_not_busy }
Busy.busy = true
runner = Thread.new(block) { block.call }
runner.join
ensure
Busy.busy = false
trap_thread.join if trap_thread
Signal.trap("INT", "DEFAULT")
end
end
end
|
.busy=(val) ⇒ Object
22
23
24
|
# File 'lib/tenderloin/busy.rb', line 22
def busy=(val)
@@busy = val
end
|
.busy? ⇒ Boolean
18
19
20
|
# File 'lib/tenderloin/busy.rb', line 18
def busy?
@@busy
end
|
.reset_trap_thread! ⇒ Object
63
64
65
|
# File 'lib/tenderloin/busy.rb', line 63
def reset_trap_thread!
@@trap_thread = nil
end
|
.trap_thread ⇒ Object
68
69
70
|
# File 'lib/tenderloin/busy.rb', line 68
def trap_thread
@@trap_thread
end
|
.wait_for_not_busy(sleeptime = 5) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/tenderloin/busy.rb', line 47
def wait_for_not_busy(sleeptime=5)
@@trap_thread ||= Thread.new do
loop do
break unless busy?
logger.info "Waiting for tenderloin to clean itself up..."
sleep sleeptime
end
logger.info "Exiting tenderloin..."
exit
end
end
|