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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddb014b67c73e8344197f534186e3a74f29a8c25
4
- data.tar.gz: e42449e681a1f1668ebde836c04d1af2258cbfff
3
+ metadata.gz: 87c2aac2892ffd9e2b44612ab5f37a1fa78388e9
4
+ data.tar.gz: 6dc7a56dee7f165c425f2272656ec773530556d3
5
5
  SHA512:
6
- metadata.gz: ede6f871ffc51e94be143f95b3a0df833f90cdbd90797b1bd2df4a71aeaea4718f8362bf09400bfa08f5ab4f4cef8c32b4f467974e09707fb26297060ecab0f6
7
- data.tar.gz: 2a6218b7778df1bfdfbec88dea2fd897cee59fe053e27946f6238502b07a8b3350d601fca3e48d06de9cb5639a6003cf89da12013cad3291dc505b819fa35b0c
6
+ metadata.gz: c341f9fb8bca656566987dee920e37be30dba4b785402cf38088275c6c15a63cb09ee9ba476839ae5d6c3f07999947e9d066e5c3638cc84fe1a3128de82d1d07
7
+ data.tar.gz: edab40f7f4331d138dc7f24b9ce1d637a740329bdea797483f0dc15ec8336eea29822cc89301a3f8027a8be1a851cac205944c13e7fed854793911b05b15d66c
data/Gemfile CHANGED
@@ -3,4 +3,8 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in sidekiq-retries.gemspec
4
4
  gemspec
5
5
 
6
- gem 'pry'
6
+ group :development, :test do
7
+ gem 'redcarpet', :platform => :ruby
8
+ gem 'yard'
9
+ gem 'pry'
10
+ end
data/HISTORY.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+ * simplify retry/fail logic
5
+ * fix retry: 0, which was going straight to the dead queue
6
+
3
7
  ## 0.1.0
4
8
 
5
9
  * sidekiq 3 compatibility
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 MyWorker
14
+ class NoRetryJob
15
15
  include Sidekiq::Worker
16
- sidekiq_options retry: false # or retry: 25, or the default...
16
+ sidekiq_options retry: false # or retry: 0
17
17
 
18
18
  def perform
19
- #force a retry even if retry: false using default retry options
20
- raise Sidekiq::Retries::Retry.new(RuntimeError.new('whatever happened'))
21
-
22
- #force a retry even if retry: false using a specific max_retries
23
- raise Sidekiq::Retries::Retry.new(RuntimeError.new('whatever happened'), 10)
24
-
25
- #if e.g. retries: true or retries: 10, skip it anyway
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'] ||= e.max_retries
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 message (for workers that retry by default)
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.17.x retry logic
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
- msg['retry_queue']
35
- else
36
- queue
37
- end
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
- msg['retried_at'] = Time.now.to_f
42
- msg['retry_count'] += 1
43
- else
44
- msg['failed_at'] = Time.now.to_f
45
- msg['retry_count'] = 0
46
- end
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
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Retries
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -17,14 +17,29 @@ module Sidekiq
17
17
  Sidekiq::RetrySet.new.clear
18
18
  end
19
19
 
20
- context 'a worker without retry' do
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' => [1],
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), 10)
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' => [1],
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.1.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-18 00:00:00.000000000 Z
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: