Module: SolidTerminator::ThreadRegistry
- Defined in:
- lib/solid_terminator/thread_registry.rb
Class Method Summary collapse
- .active_job_ids ⇒ Object
- .deregister(active_job_id, thread = nil) ⇒ Object
- .empty? ⇒ Boolean
- .purge_dead_threads ⇒ Object
- .register(active_job_id, thread = Thread.current) ⇒ Object
- .snapshot ⇒ Object
- .thread_for(active_job_id) ⇒ Object
Class Method Details
.active_job_ids ⇒ Object
25 26 27 |
# File 'lib/solid_terminator/thread_registry.rb', line 25 def active_job_ids @mutex.synchronize { @registry.keys.dup } end |
.deregister(active_job_id, thread = nil) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/solid_terminator/thread_registry.rb', line 13 def deregister(active_job_id, thread = nil) @mutex.synchronize do return if thread && !@registry[active_job_id].equal?(thread) @registry.delete(active_job_id) end end |
.empty? ⇒ Boolean
41 42 43 |
# File 'lib/solid_terminator/thread_registry.rb', line 41 def empty? @mutex.synchronize { @registry.empty? } end |
.purge_dead_threads ⇒ Object
37 38 39 |
# File 'lib/solid_terminator/thread_registry.rb', line 37 def purge_dead_threads @mutex.synchronize { @registry.delete_if { |_, t| !t.alive? } } end |
.register(active_job_id, thread = Thread.current) ⇒ Object
9 10 11 |
# File 'lib/solid_terminator/thread_registry.rb', line 9 def register(active_job_id, thread = Thread.current) @mutex.synchronize { @registry[active_job_id] = thread } end |
.snapshot ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/solid_terminator/thread_registry.rb', line 29 def snapshot @mutex.synchronize do return nil if @registry.empty? @registry.keys.dup end end |
.thread_for(active_job_id) ⇒ Object
21 22 23 |
# File 'lib/solid_terminator/thread_registry.rb', line 21 def thread_for(active_job_id) @mutex.synchronize { @registry[active_job_id] } end |