thread_watcher 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb8d1391805129dc1b7dcf1cc3b112ed1d618e85
4
- data.tar.gz: 2bbaa4d41d7813c809141f4efa372224d605bd97
3
+ metadata.gz: 6ef8e798925c24f6caf28e53d5c5f1a89b1a641d
4
+ data.tar.gz: b51f0c8cf973f109621d2e83b752c29226db10af
5
5
  SHA512:
6
- metadata.gz: 405ed31621e1cecf0902f4116dc5102d15fa58160a4a3dbe413792658dd727f50573c47a5e66c3afa4c36fd8693f6fd48c48ab1a571a9d41265b0e6b7c70139d
7
- data.tar.gz: b63b3940cf372b6d75059b5d98997fc681ea66d8226ea5ec32eecf44ea246008d7b31228f098fec46f52b2a67aa0a9fc63f257feaaa35feb250068f681301ae4
6
+ metadata.gz: 77696a7f00c917a183c97146a76991fa52fd64eb7fc5ddc1906ab501881f2d70e2699f6b13db64af13d7e2409b93df2e7b1d2fbd0a9a933cd6e103653b729897
7
+ data.tar.gz: 406729ba420b6941981625d57e3822f55a62cb155151c9b8430fbb28640d6529a849285979e8792cae697edc460c80679e0a762f307cf07263905538cc8884c8
data/README.md CHANGED
@@ -43,6 +43,25 @@ You can also specify your threads with a name if you need it.
43
43
  ThreadWatcher::Monitor.run(name:'My Job') { sleep 10 }
44
44
  ```
45
45
 
46
+ You may want to hold a process, to restart them after when he died? So you can use the keep_alive option
47
+
48
+ ```ruby
49
+ ThreadWatcher::Monitor.run(name:'My Job', keep_alive: true) { sleep 10 }
50
+ ```
51
+
52
+ Now, the process won't be killed when he's done. So you can restart them with
53
+
54
+ ```ruby
55
+ ThreadWatcher::Monitor.restart 1452333224
56
+ ```
57
+
58
+ But now, you can't kill them with `ThreadWatcher::Monitor.restart 1452333224`.
59
+ If you want to kill these process then use
60
+
61
+ ```ruby
62
+ ThreadWatcher::Monitor.kill! 1452333224
63
+ ```
64
+
46
65
  Let's say you type something like
47
66
 
48
67
  ```ruby
@@ -25,7 +25,23 @@ module ThreadWatcher
25
25
  def self.kill id
26
26
  instance.kill id
27
27
  end
28
-
28
+
29
+ def kill! id
30
+ @process_watch.kill! id
31
+ end
32
+
33
+ def self.kill! id
34
+ instance.kill! id
35
+ end
36
+
37
+ def restart id
38
+ @process_watch.restart id
39
+ end
40
+
41
+ def self.restart id
42
+ instance.restart id
43
+ end
44
+
29
45
  def status
30
46
  @process_watch.status
31
47
  end
@@ -4,7 +4,7 @@ module ThreadWatcher
4
4
  class ProcessWatch
5
5
  attr_accessor :threads
6
6
  class ThreadHolder
7
- attr_accessor :thread, :id, :options
7
+ attr_accessor :thread, :id, :options, :block
8
8
  def initialize thread, options
9
9
  @thread = thread
10
10
  @id = time_to_i
@@ -14,6 +14,10 @@ module ThreadWatcher
14
14
  def stop!
15
15
  @thread.kill
16
16
  end
17
+
18
+ def restart!
19
+ @thread = Thread.new { block.call }
20
+ end
17
21
 
18
22
  def alive?
19
23
  @thread.alive?
@@ -30,28 +34,44 @@ module ThreadWatcher
30
34
  private
31
35
 
32
36
  def available_options
33
- { :name => nil }
37
+ { :name => nil, :keep_alive => false }
34
38
  end
35
39
  end
36
40
 
37
41
  def initialize
38
42
  @threads = {}
39
- run(:name => 'Cleaning Jobs') { while true; self.clear!; sleep(60); end; }
43
+ @blocks = {}
44
+ run(:name => 'Cleaning Jobs', :keep_alive => true) { while true; self.clear!; sleep(5); end; }
40
45
  end
41
46
 
42
47
  def run options = {}, &block
43
48
  thread_holder = ThreadHolder.new(Thread.new { block.call }, options)
44
49
  thread_holder
45
50
  @threads[thread_holder.id] = thread_holder
51
+ thread_holder.block = block
46
52
  thread_holder.id
47
53
  end
48
54
 
49
55
  def kill id
50
56
  return if @threads[id].nil?
57
+ return if @threads[id].options[:keep_alive]
51
58
  @threads[id].stop!
52
59
  @threads.delete id
53
60
  end
54
61
 
62
+ def kill! id
63
+ return if @threads[id].nil?
64
+ @threads[id].options[:keep_alive] = false
65
+ kill id
66
+ ''
67
+ end
68
+
69
+ def restart id
70
+ return if @threads[id].nil?
71
+ @threads[id].restart!
72
+ ''
73
+ end
74
+
55
75
  def clear!
56
76
  @threads.each do |key, thread|
57
77
  next if thread.alive?
@@ -1,3 +1,3 @@
1
1
  module ThreadWatcher
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thread_watcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Starke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-11 00:00:00.000000000 Z
11
+ date: 2016-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler