sidekiq-retries 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -1
- data/HISTORY.md +4 -0
- data/README.md +17 -9
- data/lib/sidekiq/retries/server/middleware.rb +20 -14
- data/lib/sidekiq/retries/version.rb +1 -1
- data/spec/lib/sidekiq/retries/server/middleware_spec.rb +19 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87c2aac2892ffd9e2b44612ab5f37a1fa78388e9
|
4
|
+
data.tar.gz: 6dc7a56dee7f165c425f2272656ec773530556d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c341f9fb8bca656566987dee920e37be30dba4b785402cf38088275c6c15a63cb09ee9ba476839ae5d6c3f07999947e9d066e5c3638cc84fe1a3128de82d1d07
|
7
|
+
data.tar.gz: edab40f7f4331d138dc7f24b9ce1d637a740329bdea797483f0dc15ec8336eea29822cc89301a3f8027a8be1a851cac205944c13e7fed854793911b05b15d66c
|
data/Gemfile
CHANGED
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -11,21 +11,29 @@ Add this line to your application's Gemfile:
|
|
11
11
|
|
12
12
|
## Usage
|
13
13
|
|
14
|
-
class
|
14
|
+
class NoRetryJob
|
15
15
|
include Sidekiq::Worker
|
16
|
-
sidekiq_options retry: false
|
16
|
+
sidekiq_options retry: false # or retry: 0
|
17
17
|
|
18
18
|
def perform
|
19
|
-
#force a retry
|
20
|
-
raise Sidekiq::Retries::Retry.new(RuntimeError.new('whatever happened'))
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
# force a retry
|
20
|
+
raise Sidekiq::Retries::Retry.new(RuntimeError.new('whatever happened'))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class RetryJob
|
25
|
+
include Sidekiq::Worker
|
26
|
+
sidekiq_options retry: 25
|
27
|
+
|
28
|
+
def perform
|
29
|
+
# fail the job, don't retry it
|
26
30
|
raise Sidekiq::Retries::Fail.new(RuntimeError.new('whatever happened'))
|
27
31
|
end
|
28
32
|
end
|
33
|
+
|
34
|
+
## Caveats
|
35
|
+
|
36
|
+
* Jobs with retry: 0 don't ever appear to show up in the Sidekiq 3 Dead queue
|
29
37
|
|
30
38
|
## Contributing
|
31
39
|
|
@@ -13,11 +13,11 @@ module Sidekiq
|
|
13
13
|
raise
|
14
14
|
rescue Sidekiq::Retries::Retry => e
|
15
15
|
# force a retry (for workers that have retries disabled)
|
16
|
-
msg['retry']
|
16
|
+
msg['retry'] = e.max_retries || '1'
|
17
17
|
attempt_retry(worker, msg, queue, e.cause)
|
18
18
|
raise e.cause
|
19
19
|
rescue Sidekiq::Retries::Fail => e
|
20
|
-
# don't retry this
|
20
|
+
# seriously, don't retry this
|
21
21
|
raise e.cause
|
22
22
|
rescue Exception => e
|
23
23
|
attempt_retry(worker, msg, queue, e) if msg['retry']
|
@@ -26,24 +26,28 @@ module Sidekiq
|
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
# This is the default Sidekiq 2.
|
29
|
+
# This is the default Sidekiq 3.2.2 retry logic
|
30
30
|
def attempt_retry(worker, msg, queue, e)
|
31
|
+
# ignore, will be pushed back onto queue during hard_shutdown
|
32
|
+
raise Sidekiq::Shutdown if exception_caused_by_shutdown?(e)
|
33
|
+
|
34
|
+
raise e unless msg['retry']
|
31
35
|
max_retry_attempts = retry_attempts_from(msg['retry'], @max_retries)
|
32
36
|
|
33
37
|
msg['queue'] = if msg['retry_queue']
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
msg['error_message'] = e.message
|
38
|
+
msg['retry_queue']
|
39
|
+
else
|
40
|
+
queue
|
41
|
+
end
|
42
|
+
msg['error_message'] = e.message[0..10_000]
|
39
43
|
msg['error_class'] = e.class.name
|
40
44
|
count = if msg['retry_count']
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
msg['retried_at'] = Time.now.to_f
|
46
|
+
msg['retry_count'] += 1
|
47
|
+
else
|
48
|
+
msg['failed_at'] = Time.now.to_f
|
49
|
+
msg['retry_count'] = 0
|
50
|
+
end
|
47
51
|
|
48
52
|
if msg['backtrace'] == true
|
49
53
|
msg['error_backtrace'] = e.backtrace
|
@@ -65,6 +69,8 @@ module Sidekiq
|
|
65
69
|
# Goodbye dear message, you (re)tried your best I'm sure.
|
66
70
|
retries_exhausted(worker, msg)
|
67
71
|
end
|
72
|
+
|
73
|
+
raise e
|
68
74
|
end
|
69
75
|
|
70
76
|
end
|
@@ -17,14 +17,29 @@ module Sidekiq
|
|
17
17
|
Sidekiq::RetrySet.new.clear
|
18
18
|
end
|
19
19
|
|
20
|
-
context 'a worker
|
20
|
+
context 'a worker with retry: false' do
|
21
21
|
it 'should retry anyway if we raise a Sidekiq::Retries::Retry' do
|
22
22
|
args = {'class' => 'Bob',
|
23
|
-
'args'
|
23
|
+
'args' => [1],
|
24
24
|
'retry' => false}
|
25
25
|
expect {
|
26
26
|
handler.call(RetryWorker, args, queue) do
|
27
|
-
raise Sidekiq::Retries::Retry.new(RuntimeError.new(errmsg)
|
27
|
+
raise Sidekiq::Retries::Retry.new(RuntimeError.new(errmsg))
|
28
|
+
end
|
29
|
+
}.to raise_error(RuntimeError, errmsg)
|
30
|
+
expect(Sidekiq::RetrySet.new.size).to eq(1)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'a worker with retry: 0' do
|
36
|
+
it 'should retry anyway if we raise a Sidekiq::Retries::Retry' do
|
37
|
+
args = {'class' => 'Bob',
|
38
|
+
'args' => [1],
|
39
|
+
'retry' => 0}
|
40
|
+
expect {
|
41
|
+
handler.call(RetryWorker, args, queue) do
|
42
|
+
raise Sidekiq::Retries::Retry.new(RuntimeError.new(errmsg))
|
28
43
|
end
|
29
44
|
}.to raise_error(RuntimeError, errmsg)
|
30
45
|
expect(Sidekiq::RetrySet.new.size).to eq(1)
|
@@ -35,7 +50,7 @@ module Sidekiq
|
|
35
50
|
context 'a worker with retry' do
|
36
51
|
it 'should not retry if we raise a Sidekiq::Retries::Fail' do
|
37
52
|
args = {'class' => 'Bob',
|
38
|
-
'args'
|
53
|
+
'args' => [1],
|
39
54
|
'retry' => 2}
|
40
55
|
expect {
|
41
56
|
handler.call(RetryWorker, args, queue) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-retries
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Ortega
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -169,3 +169,4 @@ summary: Enhanced retry logic for Sidekiq workers
|
|
169
169
|
test_files:
|
170
170
|
- spec/lib/sidekiq/retries/server/middleware_spec.rb
|
171
171
|
- spec/spec_helper.rb
|
172
|
+
has_rdoc:
|