resque-retry 1.7.4 → 1.7.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: ab175830aa9de0d24e514a8bd054b1ebe8a2924ba134fd975013685e84828b9d
4
- data.tar.gz: a6cb49fb45375e4a82a8811e126f428de4acda1248d7b6cc6de5df6d9b6340bf
3
+ metadata.gz: 7a29581b3dc95632cee77ae024594ec6371f180aa2c321f2ab8867ea9b0a98fd
4
+ data.tar.gz: 6c833821432ee8fbaa5d701bf93f0ce85655a88273f550cd6fb52f1556ac2f47
5
5
  SHA512:
6
- metadata.gz: f4176df779bbc212e25d64190ae7680ee410beebb663d6b502f45fd73532b14fa4ed9f86dc76e74474dd757247b45b0a8503037a6154c814ffad159dec22413a
7
- data.tar.gz: 2109a5558025ff2d7b5b8e1cd952242aad11641b11b1036332d2f68111c1d6ca5f9de402ec92376aedff37d6dff534bed0e017196e85f451b976e405168a71da
6
+ metadata.gz: 916ae887694f4e1cf3b7acba5c444c59983d031f16f3b811b7535cd2c2bd39bfcea98ca095897558151156c76ff5f3e909600ed5150582da508aafa91242c1d9
7
+ data.tar.gz: ed7eaef67c2fc766b1bf188c8904b354d05079d591dd6cfb8c9c4191e773ece241fdf3ce37c1333300d69d1bc6b40a73deaf39956c6832919a173fc8e7f8fba3
@@ -0,0 +1,24 @@
1
+ on: [push, pull_request]
2
+
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ services:
7
+ redis:
8
+ image: redis
9
+ ports:
10
+ - 6379:6379
11
+ strategy:
12
+ matrix:
13
+ ruby-version: [2.7, 2.6, 2.5, 2.4, 2.3]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Ruby ${{ matrix.ruby-version }}
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby-version }}
21
+ - name: Install dependencies
22
+ run: bundle install
23
+ - name: Run tests
24
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -14,3 +14,5 @@ tags.*
14
14
  *.gem
15
15
  .ruby-version
16
16
  .ruby-gemset
17
+ .tags
18
+ dump.rdb
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.7.5 (2021-08-06)
2
+
3
+ * Support `retry_delay` methods with different arity
4
+ * Switch over to _GitHub_ CI for PR test-execution
5
+
1
6
  # 1.7.4 (2020-10-09)
2
7
 
3
8
  * Rework how the default `retry_limit` is calculated
@@ -1,3 +1,3 @@
1
1
  module ResqueRetry
2
- VERSION = '1.7.4'
2
+ VERSION = '1.7.5'
3
3
  end
@@ -42,10 +42,25 @@ module Resque
42
42
  )
43
43
 
44
44
  cleanup_retry_failure_log!
45
- super
46
- elsif retry_delay > 0
45
+ return super
46
+ end
47
+
48
+ # some plugins define retry_delay and have it take no arguments, so rather than break those,
49
+ # we'll just check here to see whether it takes the additional exception class argument or not
50
+ # we also allow all job args to be passed to a custom `retry_delay` method
51
+ retry_delay_arity = klass.method(:retry_delay).arity
52
+
53
+ calculated_retry_delay = if [-2, 2].include?(retry_delay_arity)
54
+ klass.retry_delay(exception.class, *args)
55
+ elsif [-1, 1].include?(retry_delay_arity)
56
+ klass.retry_delay(exception.class)
57
+ else
58
+ klass.retry_delay
59
+ end
60
+
61
+ if calculated_retry_delay > 0
47
62
  log_message(
48
- "retry_delay: #{retry_delay} > 0 - saving details in Redis",
63
+ "retry_delay: #{calculated_retry_delay} > 0 - saving details in Redis",
49
64
  args,
50
65
  exception
51
66
  )
@@ -63,12 +78,12 @@ module Resque
63
78
 
64
79
  Resque.redis.setex(
65
80
  failure_key,
66
- 2 * retry_delay,
81
+ 2 * calculated_retry_delay,
67
82
  data
68
83
  )
69
84
  else
70
85
  log_message(
71
- "retry_delay: #{retry_delay} <= 0 - ignoring",
86
+ "retry_delay: #{calculated_retry_delay} <= 0 - ignoring",
72
87
  args,
73
88
  exception
74
89
  )
@@ -117,10 +132,6 @@ module Resque
117
132
  Resque::Job.new(nil, nil).constantize(payload['class'])
118
133
  end
119
134
 
120
- def retry_delay
121
- klass.retry_delay
122
- end
123
-
124
135
  def retry_key
125
136
  klass.redis_retry_key(*payload['args'])
126
137
  end
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require_relative './test_helper'
2
2
 
3
3
  # Mock failure backend for testing MultipleWithRetrySuppression
4
4
  class MockFailureBackend < Resque::Failure::Base
@@ -25,8 +25,8 @@ class MultipleFailureTest < Minitest::Test
25
25
  Resque::Failure.backend = Resque::Failure::MultipleWithRetrySuppression
26
26
  end
27
27
 
28
- def failure_key_for(klass)
29
- 'failure-' + klass.redis_retry_key([])
28
+ def failure_key_for(klass, *args)
29
+ Resque::Failure::MultipleWithRetrySuppression.failure_key(klass.redis_retry_key(args))
30
30
  end
31
31
 
32
32
  def test_failure_is_passed_on_when_job_class_not_found
@@ -53,6 +53,22 @@ class MultipleFailureTest < Minitest::Test
53
53
  assert Resque.redis.exists(key)
54
54
  end
55
55
 
56
+ def test_retry_delay_is_calculated_with_custom_calculation
57
+ delay = 5
58
+ Resque.enqueue(DynamicDelayedJobOnExceptionAndArgs, delay.to_s)
59
+ perform_next_job(@worker)
60
+
61
+ key = failure_key_for(DynamicDelayedJobOnExceptionAndArgs, delay.to_s)
62
+ ttl = Resque.redis.ttl(key)
63
+ assert Resque.redis.exists(key)
64
+ assert MockFailureBackend.errors.size == 0
65
+
66
+ # expiration on failure_key is set to 2x the delay
67
+ # to ensure the customized delay is properly calculated using
68
+ # dynamic retry_delay method on the job
69
+ assert ttl > delay && delay <= (delay * 2)
70
+ end
71
+
56
72
  def test_retry_key_splatting_args
57
73
  # were expecting this to be called three times:
58
74
  # - once when we queue the job to try again
data/test/test_helper.rb CHANGED
@@ -20,25 +20,29 @@ require 'mocha/setup'
20
20
  require 'resque-retry'
21
21
  require dir + '/test_jobs'
22
22
 
23
- # make sure we can run redis-server
24
- if !system('which redis-server')
25
- puts '', "** `redis-server` was not found in your PATH"
26
- abort ''
27
- end
23
+ if ENV['CI'] != 'true'
24
+ # make sure we can run redis-server
25
+ if !system('which redis-server')
26
+ puts '', "** `redis-server` was not found in your PATH"
27
+ abort ''
28
+ end
28
29
 
29
- # make sure we can shutdown the server using cli.
30
- if !system('which redis-cli')
31
- puts '', "** `redis-cli` was not found in your PATH"
32
- abort ''
33
- end
30
+ # make sure we can shutdown the server using cli.
31
+ if !system('which redis-cli')
32
+ puts '', "** `redis-cli` was not found in your PATH"
33
+ abort ''
34
+ end
34
35
 
35
- # This code is run after all the tests have finished running to ensure that the
36
- # Redis server is shutdowa
37
- Minitest.after_run { `redis-cli -p 9736 shutdown nosave` }
36
+ # This code is run after all the tests have finished running to ensure that the
37
+ # Redis server is shutdowa
38
+ Minitest.after_run { `redis-cli -p 9736 shutdown nosave` }
38
39
 
39
- puts "Starting redis for testing at localhost:9736..."
40
- `redis-server #{dir}/redis-test.conf`
41
- Resque.redis = '127.0.0.1:9736'
40
+ puts "Starting redis for testing at localhost:9736..."
41
+ `redis-server #{dir}/redis-test.conf`
42
+ Resque.redis = '127.0.0.1:9736'
43
+ else
44
+ Resque.redis = '127.0.0.1:6379'
45
+ end
42
46
 
43
47
  # Test helpers
44
48
  class Minitest::Test
@@ -65,11 +69,11 @@ class Minitest::Test
65
69
 
66
70
  def delayed_jobs
67
71
  # The double-checks here are so that we won't blow up if the config stops using redis-namespace
68
- timestamps = Resque.redis.zrange("resque:delayed_queue_schedule", 0, -1) +
72
+ timestamps = Resque.redis.zrange("resque:delayed_queue_schedule", 0, -1) +
69
73
  Resque.redis.zrange("delayed_queue_schedule", 0, -1)
70
74
 
71
75
  delayed_jobs_as_json = timestamps.map do |timestamp|
72
- Resque.redis.lrange("resque:delayed:#{timestamp}", 0, -1) +
76
+ Resque.redis.lrange("resque:delayed:#{timestamp}", 0, -1) +
73
77
  Resque.redis.lrange("delayed:#{timestamp}", 0, -1)
74
78
  end.flatten
75
79
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-retry
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.4
4
+ version: 1.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Antins
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-10-09 00:00:00.000000000 Z
13
+ date: 2021-08-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: resque
@@ -161,8 +161,8 @@ executables: []
161
161
  extensions: []
162
162
  extra_rdoc_files: []
163
163
  files:
164
+ - ".github/workflows/ci.yml"
164
165
  - ".gitignore"
165
- - ".travis.yml"
166
166
  - Gemfile
167
167
  - HISTORY.md
168
168
  - LICENSE
@@ -223,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  - !ruby/object:Gem::Version
224
224
  version: '0'
225
225
  requirements: []
226
- rubygems_version: 3.1.4
226
+ rubygems_version: 3.2.22
227
227
  signing_key:
228
228
  specification_version: 4
229
229
  summary: A resque plugin; provides retry, delay and exponential backoff support for
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- language: ruby
2
-
3
- sudo: false
4
-
5
- matrix:
6
- allow_failures:
7
- - rvm: jruby-9.1.9.0
8
-
9
- rvm:
10
- - 2.3.8
11
- - 2.4.6
12
- - 2.5.5
13
- - 2.6.3
14
- - jruby-9.1.9.0