dat-worker-pool 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/dat-worker-pool/version.rb +1 -1
- data/lib/dat-worker-pool/worker.rb +13 -5
- data/test/system/dat-worker-pool_tests.rb +3 -1
- data/test/unit/worker_tests.rb +12 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
SHA512:
|
3
|
-
data.tar.gz: c0a52d7d5c533e9d71623775137e77131dcc4eceae71e4e55085f0248983442518e394fbca0aeaf02be04f6bf7484dd139ad84f4c7e165c194057d662d7689f2
|
4
|
-
metadata.gz: 8c5250174e3f695c2ad78ab377e1c29973dd37295abe65cd94d3b2a266ce0171087ab1262316004591882de23497a0e24649f8c1b0c7d75ec3cbb31fdc589938
|
5
2
|
SHA1:
|
6
|
-
|
7
|
-
|
3
|
+
metadata.gz: e1cc8332e3e05d65d1e9de7795dd3df9d2bcda89
|
4
|
+
data.tar.gz: 10cc848b2f52d31f1403b7305571db181ce7661d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d2ca49a8165cef28bd1881a36266316fa33d6216a779c5fdcc1d57584869a72375dde8f07ba20224de377f4cee707b60b6e31965b732377e8c471faee9545ba4
|
7
|
+
data.tar.gz: 6329a3d27d84eb7da54066a86064aacc0cc0f67c2125eb99fbd0a4462f4fa3d9bc088fbdf11ba7d5f04aaca21a075ae19ea111c6c6b1bbb5db4bfb8575e8853d
|
@@ -1,10 +1,18 @@
|
|
1
1
|
require 'thread'
|
2
|
+
require 'timeout'
|
2
3
|
require 'dat-worker-pool/runner'
|
3
4
|
|
4
5
|
class DatWorkerPool
|
5
6
|
|
6
7
|
module Worker
|
7
8
|
|
9
|
+
# these are standard error classes that we rescue, handle and don't reraise
|
10
|
+
# in the work loop, this keeps the worker thread from shutting down
|
11
|
+
# unexpectedly; `Timeout::Error` is a common non `StandardError` exception
|
12
|
+
# that should be treated like a `StandardError`, we don't want an uncaught
|
13
|
+
# `Timeout::Error` to shutdown a worker thread
|
14
|
+
STANDARD_ERROR_CLASSES = [StandardError, Timeout::Error].freeze
|
15
|
+
|
8
16
|
def self.included(klass)
|
9
17
|
klass.class_eval do
|
10
18
|
extend ClassMethods
|
@@ -109,13 +117,13 @@ class DatWorkerPool
|
|
109
117
|
rescue ShutdownError => exception
|
110
118
|
dwp_handle_exception(exception, work_item)
|
111
119
|
Thread.current.raise exception
|
112
|
-
rescue
|
120
|
+
rescue *STANDARD_ERROR_CLASSES => exception
|
113
121
|
dwp_handle_exception(exception, work_item)
|
114
122
|
ensure
|
115
123
|
dwp_make_available
|
116
124
|
end
|
117
125
|
end
|
118
|
-
rescue
|
126
|
+
rescue *STANDARD_ERROR_CLASSES => exception
|
119
127
|
dwp_handle_exception(exception, work_item)
|
120
128
|
end
|
121
129
|
end
|
@@ -128,7 +136,7 @@ class DatWorkerPool
|
|
128
136
|
begin
|
129
137
|
dwp_run_callback 'on_start'
|
130
138
|
dwp_make_available
|
131
|
-
rescue
|
139
|
+
rescue *STANDARD_ERROR_CLASSES => exception
|
132
140
|
dwp_handle_exception(exception)
|
133
141
|
Thread.current.raise exception
|
134
142
|
end
|
@@ -160,7 +168,7 @@ class DatWorkerPool
|
|
160
168
|
begin
|
161
169
|
dwp_make_unavailable
|
162
170
|
dwp_run_callback 'on_shutdown'
|
163
|
-
rescue
|
171
|
+
rescue *STANDARD_ERROR_CLASSES => exception
|
164
172
|
dwp_handle_exception(exception)
|
165
173
|
end
|
166
174
|
dwp_log{ "Shutdown" }
|
@@ -172,7 +180,7 @@ class DatWorkerPool
|
|
172
180
|
begin
|
173
181
|
dwp_log_exception(exception)
|
174
182
|
dwp_run_callback('on_error', exception, work_item)
|
175
|
-
rescue
|
183
|
+
rescue *STANDARD_ERROR_CLASSES => on_error_exception
|
176
184
|
# errors while running on-error callbacks are logged but otherwise
|
177
185
|
# ignored to keep the worker from crashing, ideally these should be
|
178
186
|
# caught by the on-error callbacks themselves and never get here
|
@@ -143,7 +143,9 @@ class DatWorkerPool
|
|
143
143
|
def work!(work_item)
|
144
144
|
params[:finished].push(work_item)
|
145
145
|
signal_test_suite_thread
|
146
|
-
|
146
|
+
if work_item == 'error'
|
147
|
+
raise Factory.exception(STANDARD_ERROR_CLASSES.sample)
|
148
|
+
end
|
147
149
|
end
|
148
150
|
end
|
149
151
|
# use one worker to simplify; we only need to see that one worker runs its
|
data/test/unit/worker_tests.rb
CHANGED
@@ -30,6 +30,11 @@ module DatWorkerPool::Worker
|
|
30
30
|
should have_imeths :prepend_on_error
|
31
31
|
should have_imeths :prepend_before_work, :prepend_after_work
|
32
32
|
|
33
|
+
should "know its standard error classes" do
|
34
|
+
exp = [StandardError, Timeout::Error]
|
35
|
+
assert_equal exp, DatWorkerPool::Worker::STANDARD_ERROR_CLASSES
|
36
|
+
end
|
37
|
+
|
33
38
|
should "not have any callbacks by default" do
|
34
39
|
assert_equal [], subject.on_start_callbacks
|
35
40
|
assert_equal [], subject.on_shutdown_callbacks
|
@@ -255,7 +260,7 @@ module DatWorkerPool::Worker
|
|
255
260
|
should "make itself available/unavailable and run callbacks if it errors" do
|
256
261
|
# these are the only errors that could interfere with it
|
257
262
|
error_method = [:on_unavailable_error, :work_error].sample
|
258
|
-
exception = Factory.exception
|
263
|
+
exception = Factory.exception(STANDARD_ERROR_CLASSES.sample)
|
259
264
|
subject.send("#{error_method}=", exception)
|
260
265
|
|
261
266
|
subject.dwp_start
|
@@ -303,7 +308,7 @@ module DatWorkerPool::Worker
|
|
303
308
|
end
|
304
309
|
|
305
310
|
should "run its on-error callbacks if it errors while starting" do
|
306
|
-
exception = Factory.exception
|
311
|
+
exception = Factory.exception(STANDARD_ERROR_CLASSES.sample)
|
307
312
|
error_method = [:on_start_error, :on_available_error].sample
|
308
313
|
subject.send("#{error_method}=", exception)
|
309
314
|
|
@@ -315,7 +320,7 @@ module DatWorkerPool::Worker
|
|
315
320
|
end
|
316
321
|
|
317
322
|
should "stop its thread if it errors while starting" do
|
318
|
-
exception = Factory.exception
|
323
|
+
exception = Factory.exception(STANDARD_ERROR_CLASSES.sample)
|
319
324
|
error_method = [:on_start_error, :on_available_error].sample
|
320
325
|
subject.send("#{error_method}=", exception)
|
321
326
|
|
@@ -327,7 +332,7 @@ module DatWorkerPool::Worker
|
|
327
332
|
end
|
328
333
|
|
329
334
|
should "run its on-error callbacks if it errors while shutting down" do
|
330
|
-
exception = Factory.exception
|
335
|
+
exception = Factory.exception(STANDARD_ERROR_CLASSES.sample)
|
331
336
|
error_method = [:on_shutdown_error, :on_unavailable_error].sample
|
332
337
|
subject.send("#{error_method}=", exception)
|
333
338
|
|
@@ -343,7 +348,7 @@ module DatWorkerPool::Worker
|
|
343
348
|
subject.dwp_start
|
344
349
|
wait_for_worker_to_be_available
|
345
350
|
|
346
|
-
exception = Factory.exception
|
351
|
+
exception = Factory.exception(STANDARD_ERROR_CLASSES.sample)
|
347
352
|
setup_work_loop_to_raise_exception(exception)
|
348
353
|
|
349
354
|
@queue.dwp_push(Factory.string)
|
@@ -353,7 +358,7 @@ module DatWorkerPool::Worker
|
|
353
358
|
end
|
354
359
|
|
355
360
|
should "run its on-error callbacks if an error occurs while running" do
|
356
|
-
exception = Factory.exception
|
361
|
+
exception = Factory.exception(STANDARD_ERROR_CLASSES.sample)
|
357
362
|
subject.dwp_start
|
358
363
|
wait_for_worker_to_be_available
|
359
364
|
|
@@ -367,7 +372,7 @@ module DatWorkerPool::Worker
|
|
367
372
|
end
|
368
373
|
|
369
374
|
should "not stop its thread if an error occurs in an on-error callback" do
|
370
|
-
exception = Factory.exception
|
375
|
+
exception = Factory.exception(STANDARD_ERROR_CLASSES.sample)
|
371
376
|
subject.dwp_start
|
372
377
|
wait_for_worker_to_be_available
|
373
378
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dat-worker-pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Collin Redding
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2016-06-
|
13
|
+
date: 2016-06-24 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: assert
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
requirements: []
|
95
95
|
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.5.1
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: A simple thread pool for processing generic 'work'
|