Class: ThreadWatcher::ProcessWatch
- Inherits:
-
Object
- Object
- ThreadWatcher::ProcessWatch
- Defined in:
- lib/thread_watcher/process_watch.rb
Instance Attribute Summary collapse
-
#threads ⇒ Object
Returns the value of attribute threads.
Instance Method Summary collapse
- #clear! ⇒ Object
-
#initialize ⇒ ProcessWatch
constructor
A new instance of ProcessWatch.
- #kill(id) ⇒ Object
- #kill!(id) ⇒ Object
- #restart(id) ⇒ Object
- #run(options = {}, &block) ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize ⇒ ProcessWatch
Returns a new instance of ProcessWatch.
5 6 7 8 9 |
# File 'lib/thread_watcher/process_watch.rb', line 5 def initialize @threads = {} @current_id = 1 start_cleaning_job end |
Instance Attribute Details
#threads ⇒ Object
Returns the value of attribute threads.
3 4 5 |
# File 'lib/thread_watcher/process_watch.rb', line 3 def threads @threads end |
Instance Method Details
#clear! ⇒ Object
39 40 41 42 43 44 |
# File 'lib/thread_watcher/process_watch.rb', line 39 def clear! @threads.each do |key, thread| next if thread.alive? kill key end end |
#kill(id) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/thread_watcher/process_watch.rb', line 19 def kill id return if @threads[id].nil? return if @threads[id].[:keep_alive] @threads[id].stop! @threads.delete id end |
#kill!(id) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/thread_watcher/process_watch.rb', line 26 def kill! id return if @threads[id].nil? @threads[id].[:keep_alive] = false kill id '' end |
#restart(id) ⇒ Object
33 34 35 36 37 |
# File 'lib/thread_watcher/process_watch.rb', line 33 def restart id return if @threads[id].nil? @threads[id].restart! '' end |
#run(options = {}, &block) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/thread_watcher/process_watch.rb', line 11 def run = {}, &block = .merge(id: next_id) thread_holder = ThreadHolder.new(block, ) thread_holder.start! @threads[thread_holder.id] = thread_holder thread_holder.id end |
#status ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/thread_watcher/process_watch.rb', line 46 def status ThreadFormatter.headline @threads.each do |key, thread| ThreadFormatter.data thread end '' end |