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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6cda82b0f03df2130e38841bff942ab7f3d559a1c6233121c6060a7c06d50d0
4
- data.tar.gz: 64b0c6ba8e659ff3dcc4009b5c13ba91139e7f82a6043f42c0d3eed6c0368107
3
+ metadata.gz: 41fdd839e9d646bc4cff92ec6eda63da5ad24f4d683e9bc42ce167547247fb29
4
+ data.tar.gz: 317c5da4cbd865d36d4361920f906456f4205ce3f5f09376af15aa7798347175
5
5
  SHA512:
6
- metadata.gz: '0998ffd89b16233c8fa97fa00b8db4de490f9dccdebc7a6002a5d44a0ac859a050a41e339c545f6ec5ebfaa9888671b693cf389a779975c214b54cd9328385d4'
7
- data.tar.gz: 9b2d2d1fc6e3d2667286c9a5f48a247596612a9b0162b4cc202b536f43745a55894d35f45e2efd5badf431cbaea0a47f9108262d1d24252bf4410222d7eb58e5
6
+ metadata.gz: 6e1138796a7bfae97429073564862ecd3619576ef88e28a3a043550cd054b82fac2ac79f67931080604c91e73b4356c56798d7b2801e2a9e6e8e448ea8ed31e0
7
+ data.tar.gz: 5f08e73f3a4b816b59c32c902103b39e8d53d42bb8528eed02af0e73fbea576a788e24687cabb482cc652bb259fe40ee35d216f1010b48f4439aa1b52715d0dd
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.3.0
4
+ - 2.5.0
4
5
  services:
5
6
  - mysql
6
7
  before_install:
@@ -1,5 +1,10 @@
1
1
  # Workhorse Change log
2
2
 
3
+ ## 0.3.5 - unreleased
4
+
5
+ * Adds global callback `on_exception` that allows custom exception handling /
6
+ exception notification.
7
+
3
8
  ## 0.3.4 - 2018-09-24
4
9
 
5
10
  * *Fixes #14
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.4
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
@@ -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
 
@@ -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
@@ -134,6 +134,8 @@ module Workhorse
134
134
  end
135
135
  end
136
136
  end
137
+ rescue => e
138
+ Workhorse.on_exception.call(e)
137
139
  end
138
140
 
139
141
  private
@@ -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
@@ -1,16 +1,16 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: workhorse 0.3.4 ruby lib
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.4"
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-09-24"
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.5.2.3".freeze
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
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-09-24 00:00:00.000000000 Z
11
+ date: 2018-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler