Class: ThreadWatcher::ProcessWatch

Inherits:
Object
  • Object
show all
Defined in:
lib/thread_watcher/process_watch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProcessWatch

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

#threadsObject

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].options[: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].options[: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 options = {}, &block
  thread_holder = ThreadHolder.new(block, options)
  thread_holder.start!
  @threads[thread_holder.id] = thread_holder
  thread_holder.id
end

#statusObject



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