delayed-threaded 0.17.1 → 0.18.0

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
  SHA1:
3
- metadata.gz: ce6a3948e6a0ceea302b0645c284c392dae15b19
4
- data.tar.gz: 6fe497718a6c6cc06b010e13e8a1c477ded4b228
3
+ metadata.gz: d13a30f15238ded42f550c3dc05217c02c06d675
4
+ data.tar.gz: 52577b78b63953c53e387c464cab2710b0c3cacc
5
5
  SHA512:
6
- metadata.gz: 1dd596551baf39bb987209f5b136c5d34a55a6deec73206c441175a2d8034e9c5b44a80bb44b1d1d3649a808223596a3e460c0f4c3b0a64e92026223aaa5ae8b
7
- data.tar.gz: 18dc0ba741a33056f789f03b79c7b972647ae4945bbf00c94e671ddcece7196aa56f1ade89b3c0341b24a8b425b50fbb55b66b26c72ac415c958750e114a5ed6
6
+ metadata.gz: fa250193345448aebe7e5b075095a6c0f50bdb9ded1ea07e00d4796df454eb43e1c913c4053bba8490d23d811c2dfd2d0034a599aa81963d69f460568e60065b
7
+ data.tar.gz: 227b9f9b1960c8c3e51218018dd1de96cdaec2b1ed06a35f8661aecdb1d7edd9be7d1c93b5a72fba1c71e7f1e40e00ff68f4945cef8561c8e53e0dd69d7944af
data/README.md CHANGED
@@ -55,6 +55,17 @@ the connections after work (as the worker sleeps), setup as a plugin using :
55
55
  require 'delayed/active_record/release_connection_plugin.rb'
56
56
  ````
57
57
 
58
+ and a somehow fail-"safer" lock clearing mechanism in case of backend errors
59
+
60
+ ```ruby
61
+ # Replace DJ's default ClearLocks plugin with a fail-safe version
62
+ # e.g. when a connection goes down in the middle of job processing,
63
+ # `Delayed::Job.clear_locks!` causes a double fault to propagate.
64
+ require 'delayed/fail_safe/clear_locks_plugin.rb'
65
+ ```
66
+
67
+ NOTE: **delayed_job** might not be the right tool for a fail-safe worker job.
68
+
58
69
  ## Development
59
70
 
60
71
  After checking out the repo, run `bin/setup` to install dependencies.
@@ -0,0 +1,38 @@
1
+ module Delayed
2
+ module FailSafe
3
+ class ClearLocks < Plugin
4
+
5
+ @@exception_handler = lambda do |ex, worker| # fail-safe by default
6
+ worker.say "Error running clear_locks! callback: #{ex.inspect}", 'error'
7
+ end
8
+
9
+ # Allow user customizations of error handling.
10
+ #
11
+ # To get the same behavior as `Delayed::Plugins::ClearLocks` :
12
+ #
13
+ # Delayed::FailSafe::ClearLocks.exception_handler { |ex| raise(ex) }
14
+ #
15
+ def self.exception_handler(&block)
16
+ return @@exception_handler unless block_given?
17
+ @@exception_handler = block
18
+ end
19
+
20
+ def self.call(worker)
21
+ Delayed::Job.clear_locks!(worker.name)
22
+ rescue => ex
23
+ @@exception_handler.call(ex, worker)
24
+ end
25
+
26
+ callbacks do |lifecycle|
27
+ lifecycle.around(:execute) do |worker, &block|
28
+ begin
29
+ block.call(worker)
30
+ ensure
31
+ ClearLocks.call(worker)
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ require 'delayed/worker'
2
+
3
+ require 'delayed/fail_safe/clear_locks'
4
+ if defined? Delayed::Plugins::ClearLocks
5
+ i = Delayed::Worker.plugins.index(Delayed::Plugins::ClearLocks) || 0
6
+ Delayed::Worker.plugins[i] = Delayed::FailSafe::ClearLocks
7
+ end
@@ -1,5 +1,5 @@
1
1
  module Delayed
2
2
  module Threaded
3
- VERSION = '0.17.1'
3
+ VERSION = '0.18.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed-threaded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.1
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karol Bucek
@@ -118,6 +118,8 @@ files:
118
118
  - delayed-threaded.gemspec
119
119
  - lib/delayed/active_record/release_connection_plugin.rb
120
120
  - lib/delayed/backend/active_record/release_connection.rb
121
+ - lib/delayed/fail_safe/clear_locks.rb
122
+ - lib/delayed/fail_safe/clear_locks_plugin.rb
121
123
  - lib/delayed/threaded.rb
122
124
  - lib/delayed/threaded/sleep_calculator.rb
123
125
  - lib/delayed/threaded/sync_lifecycle.rb