workhorse 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +5 -0
- data/README.md +17 -0
- data/VERSION +1 -1
- data/lib/generators/workhorse/templates/config/initializers/workhorse.rb +8 -0
- data/lib/workhorse.rb +6 -0
- data/lib/workhorse/performer.rb +4 -0
- data/lib/workhorse/worker.rb +2 -0
- data/test/lib/jobs.rb +8 -0
- data/test/workhorse/performer_test.rb +16 -0
- data/workhorse.gemspec +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41fdd839e9d646bc4cff92ec6eda63da5ad24f4d683e9bc42ce167547247fb29
|
4
|
+
data.tar.gz: 317c5da4cbd865d36d4361920f906456f4205ce3f5f09376af15aa7798347175
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e1138796a7bfae97429073564862ecd3619576ef88e28a3a043550cd054b82fac2ac79f67931080604c91e73b4356c56798d7b2801e2a9e6e8e448ea8ed31e0
|
7
|
+
data.tar.gz: 5f08e73f3a4b816b59c32c902103b39e8d53d42bb8528eed02af0e73fbea576a788e24687cabb482cc652bb259fe40ee35d216f1010b48f4439aa1b52715d0dd
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -240,6 +240,23 @@ Workhorse::Daemon::ShellHandler.run count: 5 do
|
|
240
240
|
end
|
241
241
|
```
|
242
242
|
|
243
|
+
## Exception handling
|
244
|
+
|
245
|
+
Per default, exceptions occurring in a worker thread will only be visible in the
|
246
|
+
respective log file, usually `production.log`. If you'd like to perform specific
|
247
|
+
actions when an exception arises, set the global option `on_exception` to a
|
248
|
+
callback of your linking, e.g.:
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
# config/initializers/workhorse.rb
|
252
|
+
Workhorse.setup do |config|
|
253
|
+
config.on_exception = proc do |e|
|
254
|
+
# Use gem 'exception_notification' for notifying about exceptions
|
255
|
+
ExceptionNotifier.notify_exception(exception)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
```
|
259
|
+
|
243
260
|
## Frequently asked questions
|
244
261
|
|
245
262
|
Please consult the [FAQ](FAQ.md).
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.5
|
@@ -11,4 +11,12 @@ Workhorse.setup do |config|
|
|
11
11
|
# config.tx_callback = proc do |&block|
|
12
12
|
# ActiveRecord::Base.transaction&(&block)
|
13
13
|
# end
|
14
|
+
|
15
|
+
# Enable and configure this to specify a callback for handling worker
|
16
|
+
# exceptions:
|
17
|
+
#
|
18
|
+
# config.on_exception = proc do |exception|
|
19
|
+
# # Do something with exception, i.e.
|
20
|
+
# # ExceptionNotifier.notify_exception(exception)
|
21
|
+
# end
|
14
22
|
end
|
data/lib/workhorse.rb
CHANGED
@@ -25,6 +25,12 @@ module Workhorse
|
|
25
25
|
ActiveRecord::Base.transaction(&block)
|
26
26
|
end
|
27
27
|
|
28
|
+
mattr_accessor :on_exception
|
29
|
+
self.on_exception = proc do |exception|
|
30
|
+
# Do something with this exception, i.e.
|
31
|
+
# ExceptionNotifier.notify_exception(exception)
|
32
|
+
end
|
33
|
+
|
28
34
|
mattr_accessor :perform_jobs_in_tx
|
29
35
|
self.perform_jobs_in_tx = true
|
30
36
|
|
data/lib/workhorse/performer.rb
CHANGED
@@ -12,6 +12,8 @@ module Workhorse
|
|
12
12
|
fail 'Performer can only run once.' if @started
|
13
13
|
@started = true
|
14
14
|
perform!
|
15
|
+
rescue => e
|
16
|
+
Workhorse.on_exception.call(e)
|
15
17
|
end
|
16
18
|
|
17
19
|
private
|
@@ -38,6 +40,8 @@ module Workhorse
|
|
38
40
|
log 'Mark failed', :debug
|
39
41
|
@db_job.mark_failed!(e)
|
40
42
|
end
|
43
|
+
|
44
|
+
fail e
|
41
45
|
ensure
|
42
46
|
Thread.current[:workhorse_current_performer] = nil
|
43
47
|
end
|
data/lib/workhorse/worker.rb
CHANGED
data/test/lib/jobs.rb
CHANGED
@@ -22,6 +22,14 @@ class DbConnectionTestJob
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
class FailingTestJob
|
26
|
+
MESSAGE = 'I fail all the time'.freeze
|
27
|
+
|
28
|
+
def perform
|
29
|
+
fail MESSAGE
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
25
33
|
class DummyRailsOpsOp
|
26
34
|
class_attribute :results
|
27
35
|
self.results = Concurrent::Array.new
|
@@ -13,4 +13,20 @@ class Workhorse::WorkerTest < WorkhorseTest
|
|
13
13
|
assert_equal 2, DbConnectionTestJob.db_connections.count
|
14
14
|
assert_equal 2, DbConnectionTestJob.db_connections.uniq.count
|
15
15
|
end
|
16
|
+
|
17
|
+
def test_on_exception
|
18
|
+
old_callback = Workhorse.on_exception
|
19
|
+
exception = nil
|
20
|
+
|
21
|
+
Workhorse.on_exception = proc do |e|
|
22
|
+
exception = e
|
23
|
+
end
|
24
|
+
|
25
|
+
Workhorse.enqueue FailingTestJob.new
|
26
|
+
work 0.2, polling_interval: 0.2
|
27
|
+
|
28
|
+
assert_equal exception.message, FailingTestJob::MESSAGE
|
29
|
+
ensure
|
30
|
+
Workhorse.on_exception = old_callback
|
31
|
+
end
|
16
32
|
end
|
data/workhorse.gemspec
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: workhorse 0.3.
|
2
|
+
# stub: workhorse 0.3.5 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "workhorse".freeze
|
6
|
-
s.version = "0.3.
|
6
|
+
s.version = "0.3.5"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Sitrox".freeze]
|
11
|
-
s.date = "2018-
|
11
|
+
s.date = "2018-10-22"
|
12
12
|
s.files = [".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".travis.yml".freeze, "CHANGELOG.md".freeze, "FAQ.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "RUBY_VERSION".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/rubocop".freeze, "lib/generators/workhorse/install_generator.rb".freeze, "lib/generators/workhorse/templates/bin/workhorse.rb".freeze, "lib/generators/workhorse/templates/config/initializers/workhorse.rb".freeze, "lib/generators/workhorse/templates/create_table_jobs.rb".freeze, "lib/workhorse.rb".freeze, "lib/workhorse/daemon.rb".freeze, "lib/workhorse/daemon/shell_handler.rb".freeze, "lib/workhorse/db_job.rb".freeze, "lib/workhorse/enqueuer.rb".freeze, "lib/workhorse/jobs/cleanup_succeeded_jobs.rb".freeze, "lib/workhorse/jobs/run_rails_op.rb".freeze, "lib/workhorse/performer.rb".freeze, "lib/workhorse/poller.rb".freeze, "lib/workhorse/pool.rb".freeze, "lib/workhorse/worker.rb".freeze, "test/lib/db_schema.rb".freeze, "test/lib/jobs.rb".freeze, "test/lib/test_helper.rb".freeze, "test/workhorse/enqueuer_test.rb".freeze, "test/workhorse/performer_test.rb".freeze, "test/workhorse/poller_test.rb".freeze, "test/workhorse/pool_test.rb".freeze, "test/workhorse/worker_test.rb".freeze, "workhorse.gemspec".freeze]
|
13
|
-
s.rubygems_version = "2.
|
13
|
+
s.rubygems_version = "2.7.6".freeze
|
14
14
|
s.summary = "Multi-threaded job backend with database queuing for ruby.".freeze
|
15
15
|
s.test_files = ["test/lib/db_schema.rb".freeze, "test/lib/jobs.rb".freeze, "test/lib/test_helper.rb".freeze, "test/workhorse/enqueuer_test.rb".freeze, "test/workhorse/performer_test.rb".freeze, "test/workhorse/poller_test.rb".freeze, "test/workhorse/pool_test.rb".freeze, "test/workhorse/worker_test.rb".freeze]
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workhorse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sitrox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|