resque-retry 1.7.4 → 1.7.6

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: bcd42f2b0761226dd2cfa5f9c9d4ff336cda1be0f6acf972ae15cd553f88fa0b
4
+ data.tar.gz: d65b4261a3ff1068f9880739ea1f4647c10be957511840203331f714cb8281dc
5
5
  SHA512:
6
- metadata.gz: f4176df779bbc212e25d64190ae7680ee410beebb663d6b502f45fd73532b14fa4ed9f86dc76e74474dd757247b45b0a8503037a6154c814ffad159dec22413a
7
- data.tar.gz: 2109a5558025ff2d7b5b8e1cd952242aad11641b11b1036332d2f68111c1d6ca5f9de402ec92376aedff37d6dff534bed0e017196e85f451b976e405168a71da
6
+ metadata.gz: 78c8fccf7a670f1fc0246d7e8862941eae3fb2bda8ea4d11fb1bea2a5890ed1867f50ff9389a752f3383bf5383783b32e3f63c5ef623909a28aaeba62f4576a2
7
+ data.tar.gz: 8e3e0ed80d154282e6dddd85b8b7b95b22949d580ad6c0c7a0fc9c3a16475dca861320f919db0f2ddf6b8dca78e8bdd846a48b86db6a5761848d6d4fcb7012a4
@@ -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]
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,14 @@
1
+ # 1.7.6 (2021-08-06)
2
+
3
+ * Fix Redis 4.3 breaking saving job failures with multiple failure backend
4
+ * Disable verbose logging by default during test-runs
5
+ * Remove support for ruby < 2.6
6
+
7
+ # 1.7.5 (2021-08-06)
8
+
9
+ * Support `retry_delay` methods with different arity
10
+ * Switch over to _GitHub_ CI for PR test-execution
11
+
1
12
  # 1.7.4 (2020-10-09)
2
13
 
3
14
  * 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.6'
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
@@ -132,7 +143,17 @@ module Resque
132
143
  end
133
144
 
134
145
  def retrying?
135
- Resque.redis.exists(retry_key)
146
+ redis_key_exists?(retry_key)
147
+ end
148
+
149
+ private
150
+
151
+ def redis_key_exists?(key)
152
+ if Resque.redis.respond_to?(:exists?)
153
+ Resque.redis.exists?(key)
154
+ else
155
+ ![false, 0].include?(Resque.redis.exists(key) || false)
156
+ end
136
157
  end
137
158
  end
138
159
  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
@@ -141,6 +157,20 @@ class MultipleFailureTest < Minitest::Test
141
157
  end
142
158
  end
143
159
 
160
+ def test_redis_exists_returns_integer
161
+ Resque.enqueue(RetryDefaultsJob)
162
+ original = Redis.exists_returns_integer
163
+ Redis.exists_returns_integer = true
164
+
165
+ 3.times do
166
+ perform_next_job(@worker)
167
+ end
168
+
169
+ Redis.exists_returns_integer = original
170
+
171
+ assert_equal 1, MockFailureBackend.errors.size
172
+ end
173
+
144
174
  def teardown
145
175
  Resque::Failure.backend = @old_failure_backend
146
176
  end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  dir = File.dirname(File.expand_path(__FILE__))
2
2
  $LOAD_PATH.unshift dir + '/../lib'
3
+
3
4
  $TESTING = true
5
+ $VERBOSE = ENV['VERBOSE'] != 'true' ? nil : true
4
6
 
5
7
  # Run code coverage in MRI 1.9 only.
6
8
  if RUBY_VERSION >= '1.9' && RUBY_ENGINE == 'ruby'
@@ -20,25 +22,29 @@ require 'mocha/setup'
20
22
  require 'resque-retry'
21
23
  require dir + '/test_jobs'
22
24
 
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
25
+ if ENV['CI'] != 'true'
26
+ # make sure we can run redis-server
27
+ if !system('which redis-server')
28
+ puts '', "** `redis-server` was not found in your PATH"
29
+ abort ''
30
+ end
28
31
 
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
32
+ # make sure we can shutdown the server using cli.
33
+ if !system('which redis-cli')
34
+ puts '', "** `redis-cli` was not found in your PATH"
35
+ abort ''
36
+ end
34
37
 
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` }
38
+ # This code is run after all the tests have finished running to ensure that the
39
+ # Redis server is shutdowa
40
+ Minitest.after_run { `redis-cli -p 9736 shutdown nosave` }
38
41
 
39
- puts "Starting redis for testing at localhost:9736..."
40
- `redis-server #{dir}/redis-test.conf`
41
- Resque.redis = '127.0.0.1:9736'
42
+ puts "Starting redis for testing at localhost:9736..."
43
+ `redis-server #{dir}/redis-test.conf`
44
+ Resque.redis = '127.0.0.1:9736'
45
+ else
46
+ Resque.redis = '127.0.0.1:6379'
47
+ end
42
48
 
43
49
  # Test helpers
44
50
  class Minitest::Test
@@ -65,11 +71,11 @@ class Minitest::Test
65
71
 
66
72
  def delayed_jobs
67
73
  # 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) +
74
+ timestamps = Resque.redis.zrange("resque:delayed_queue_schedule", 0, -1) +
69
75
  Resque.redis.zrange("delayed_queue_schedule", 0, -1)
70
76
 
71
77
  delayed_jobs_as_json = timestamps.map do |timestamp|
72
- Resque.redis.lrange("resque:delayed:#{timestamp}", 0, -1) +
78
+ Resque.redis.lrange("resque:delayed:#{timestamp}", 0, -1) +
73
79
  Resque.redis.lrange("delayed:#{timestamp}", 0, -1)
74
80
  end.flatten
75
81
 
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.6
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