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 |
# File 'lib/thread_watcher/process_watch.rb', line 5 def initialize @threads = {} 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
37 38 39 40 41 42 |
# File 'lib/thread_watcher/process_watch.rb', line 37 def clear! @threads.each do |key, thread| next if thread.alive? kill key end end |
#kill(id) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/thread_watcher/process_watch.rb', line 17 def kill id return if @threads[id].nil? return if @threads[id].[:keep_alive] @threads[id].stop! @threads.delete id end |
#kill!(id) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/thread_watcher/process_watch.rb', line 24 def kill! id return if @threads[id].nil? @threads[id].[:keep_alive] = false kill id '' end |
#restart(id) ⇒ Object
31 32 33 34 35 |
# File 'lib/thread_watcher/process_watch.rb', line 31 def restart id return if @threads[id].nil? @threads[id].restart! '' end |
#run(options = {}, &block) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/thread_watcher/process_watch.rb', line 10 def run = {}, &block thread_holder = ThreadHolder.new(block, ) thread_holder.start! @threads[thread_holder.id] = thread_holder thread_holder.id end |
#status ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/thread_watcher/process_watch.rb', line 44 def status ThreadFormatter.headline @threads.each do |key, thread| ThreadFormatter.data thread end '' end |