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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3fd2f85141d2afb0d63d951055f8f1e4d7663e6d
4
- data.tar.gz: cf0a2c43b82526ca9dbb8bf1cf1d25bb6a5423ba
3
+ metadata.gz: 0643646db53469fb6c0d87b95ce6cff8b7946a82
4
+ data.tar.gz: 3d5c113c200c46f87f6ae1f4d4ebf104e1ce4e46
5
5
  SHA512:
6
- metadata.gz: c059a1dd5e8d98c15787232feab596c6f1590fab0548f92de208bd3750d9b3a08f0524b949e7e39b4e697009be00eb2c33e4e32e6753e9db56abad3089bbc3c3
7
- data.tar.gz: dc220145724e80fefc815c12b6a88355c0823521b543da5b195acd906e3518dac134b8cde66025f3cd4f10509687bb824e79c8aebb6ccc19c945f7af267e489e
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.5.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
- |1452405225 |true | 120 |
66
- |1452405227 |true | 118 |
67
- |1452405228 |true | 117 |
68
- |1452405334 |false | 11 |
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
@@ -1,3 +1,3 @@
1
1
  module ThreadWatcher
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -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.5.1
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-10 00:00:00.000000000 Z
11
+ date: 2016-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler