thread_watcher 0.5.1 → 0.6.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 +4 -4
- data/README.md +14 -6
- data/lib/thread_watcher/process_watch.rb +13 -5
- data/lib/thread_watcher/thread_formatter.rb +2 -2
- data/lib/thread_watcher/version.rb +1 -1
- data/lib/thread_watcher.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0643646db53469fb6c0d87b95ce6cff8b7946a82
|
4
|
+
data.tar.gz: 3d5c113c200c46f87f6ae1f4d4ebf104e1ce4e46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31347359ed83b94c55147131ce3702fdf0020b72d9125694e4d510b0daf4f2ace0aaced05448371f64cab0d86c3b0aebbf3b1bc0f291855ed59144ce436c8672
|
7
|
+
data.tar.gz: df6011147e47a23f213baf30d0db23bd298ac8ea1103545f7ce80ba0cb42784b275b09928f5dc6ed3c1b2b508f47d6c20e7d36fe0bd0a53c6b1822e04ab72e5b
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ You need to monitor your threads and kill one specific thread in another part of
|
|
8
8
|
hm, yeah. just add this to your Gemfile:
|
9
9
|
|
10
10
|
```ruby
|
11
|
-
gem 'thread_watcher', '~> 0.
|
11
|
+
gem 'thread_watcher', '~> 0.6.0'
|
12
12
|
```
|
13
13
|
|
14
14
|
And then execute:
|
@@ -37,6 +37,12 @@ This could be something like `1452333019`
|
|
37
37
|
If your thread is ok, so let them work.
|
38
38
|
ThreadWatcher starts automaticly a cleaning task to kill dead threads every minute.
|
39
39
|
|
40
|
+
You can also specify your threads with a name if you need it.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
ThreadWatcher::Monitor.run(name:'My Job') { sleep 10 }
|
44
|
+
```
|
45
|
+
|
40
46
|
Let's say you type something like
|
41
47
|
|
42
48
|
```ruby
|
@@ -61,11 +67,13 @@ If you need more information about these threads so use
|
|
61
67
|
And you get a simple overview like
|
62
68
|
|
63
69
|
```
|
64
|
-
|ID |Running? |Runtime in Seconds |
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
|ID |Running? |Runtime in Seconds |Name
|
71
|
+
|1452537945 |true | 177 |Cleaning Jobs
|
72
|
+
|1452538091 |false | 31 |sleeper9
|
73
|
+
|1452538106 |true | 16 |
|
74
|
+
|1452538116 |true | 6 |sleeper50
|
75
|
+
|1452538121 |true | 1 |sleeper30
|
76
|
+
|
69
77
|
|
70
78
|
```
|
71
79
|
|
@@ -4,10 +4,11 @@ module ThreadWatcher
|
|
4
4
|
class ProcessWatch
|
5
5
|
attr_accessor :threads
|
6
6
|
class ThreadHolder
|
7
|
-
attr_accessor :thread, :id
|
8
|
-
def initialize thread
|
7
|
+
attr_accessor :thread, :id, :options
|
8
|
+
def initialize thread, options
|
9
9
|
@thread = thread
|
10
10
|
@id = time_to_i
|
11
|
+
@options = available_options.merge options
|
11
12
|
end
|
12
13
|
|
13
14
|
def stop!
|
@@ -25,15 +26,22 @@ module ThreadWatcher
|
|
25
26
|
def time_to_i
|
26
27
|
Time.now.to_i
|
27
28
|
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def available_options
|
33
|
+
{ name: nil }
|
34
|
+
end
|
28
35
|
end
|
29
36
|
|
30
37
|
def initialize
|
31
38
|
@threads = {}
|
32
|
-
run { while true; self.clear!; sleep(60); end; }
|
39
|
+
run(name:'Cleaning Jobs') { while true; self.clear!; sleep(60); end; }
|
33
40
|
end
|
34
41
|
|
35
|
-
def run &block
|
36
|
-
thread_holder = ThreadHolder.new(Thread.new { block.call })
|
42
|
+
def run options = {}, &block
|
43
|
+
thread_holder = ThreadHolder.new(Thread.new { block.call }, options)
|
44
|
+
thread_holder
|
37
45
|
@threads[thread_holder.id] = thread_holder
|
38
46
|
thread_holder.id
|
39
47
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module ThreadWatcher
|
2
2
|
class ThreadFormatter
|
3
3
|
def self.headline
|
4
|
-
self.output "|ID\t\t|Running?\t|Runtime in Seconds\t|"
|
4
|
+
self.output "|ID\t\t|Running?\t|Runtime in Seconds\t|Name"
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.data thread
|
8
|
-
self.output "|#{thread.id}\t|#{thread.alive?}\t\t|\t#{thread.runtime}\t\t
|
8
|
+
self.output "|#{thread.id}\t|#{thread.alive?}\t\t|\t#{thread.runtime}\t\t|#{thread.options[:name]}"
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.output content
|
data/lib/thread_watcher.rb
CHANGED
@@ -10,12 +10,12 @@ module ThreadWatcher
|
|
10
10
|
@process_watch = ThreadWatcher::ProcessWatch.new
|
11
11
|
end
|
12
12
|
|
13
|
-
def run &block
|
14
|
-
@process_watch.run &block
|
13
|
+
def run options = {}, &block
|
14
|
+
@process_watch.run options, &block
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.run &block
|
18
|
-
instance.run &block
|
17
|
+
def self.run options = {}, &block
|
18
|
+
instance.run options, &block
|
19
19
|
end
|
20
20
|
|
21
21
|
def kill id
|
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.
|
4
|
+
version: 0.6.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
|
+
date: 2016-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|