resque-integration 3.4.1 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d09663fd4ebbbdeab2821981399c99d590c4d1f4
4
- data.tar.gz: ae7c8f47a7b88af93bf6e5e46577f4e95ae8bcac
3
+ metadata.gz: b25c3af3ff9bec74ef1a6c8355f622a8d8ed916a
4
+ data.tar.gz: fcebf66e66aeb96194e051ddf3381efb4b828ed1
5
5
  SHA512:
6
- metadata.gz: f3029f15b7082a53034862bdb3d0b9aae77784ac95f9dc73c05966abd881d722a7e5285ea8e83f28697a77f8d2dc6266d8c89e82e25b5d65a4c7564d3e105fcf
7
- data.tar.gz: 2aebb5a7298e3bb1713f0490e4062445d74f600b657d47e77d27b06d64dfbd34a0e90ca3aa481c4eefb2169fb62f86dd4567835249f2737de02fcbcb328d526b
6
+ metadata.gz: 151ccd775abb8e8df97149a90cdbe679a87367c6fb4a91b05116b45000f9d6eb83bfc773331c05ed87bfdc7a2eabf80c705c27d889f59c5aaa9408ed8dcb0659
7
+ data.tar.gz: 0c1a6450232a75c71d18168622b5db0b9069e15ca58befd2f67624e22a705965838887308ad75a198240ec9ff2114e43d69fba479734dac447ef206f1300f4da
data/.drone.yml CHANGED
@@ -10,7 +10,7 @@ build:
10
10
  - COMPOSE_FILE_EXT=drone
11
11
  - RUBY_IMAGE_TAG=2.2-latest
12
12
  commands:
13
- - wrapdocker docker -v
13
+ - prepare-build
14
14
 
15
15
  - fetch-images --image abakpress/ruby-app:$RUBY_IMAGE_TAG
16
16
  - dip provision
data/CHANGELOG.md CHANGED
@@ -1,7 +1,14 @@
1
- # v3.4.1
1
+ # v3.5.0
2
2
 
3
+ * 2018-09-06 [49717a5](../../commit/49717a5) - __(Mikhail Nelaev)__ Release 3.5.0
3
4
  * 2018-08-21 [b56dcc8](../../commit/b56dcc8) - __(Artem Napolskih)__ chore: Add automatic publication
4
5
  * 2018-08-15 [5e90b55](../../commit/5e90b55) - __(Artem Napolskih)__ feat: rails 5-x support added
6
+ * 2018-08-09 [3fa8ce0](../../commit/3fa8ce0) - __(terentev)__ feat: move temporary_exceptions to yml config
7
+ https://jira.railsc.ru/browse/GOODS-1418
8
+
9
+ * 2018-08-02 [528feab](../../commit/528feab) - __(terentev)__ feat: adds ability for retry jobs after temporary errors
10
+ https://jira.railsc.ru/browse/GOODS-1418
11
+
5
12
  * 2018-06-05 [3fc2608](../../commit/3fc2608) - __(Pavel Galkin)__ Release 3.4.0
6
13
  * 2018-06-05 [6ec7a38](../../commit/6ec7a38) - __(Pavel Galkin)__ feat: resque:expire task
7
14
  https://jira.railsc.ru/browse/PC4-21225
@@ -209,6 +209,24 @@ module Resque
209
209
  self['resque.god_log_level'] || 'info'
210
210
  end
211
211
 
212
+ # Public: Temporary exceptions.
213
+ #
214
+ # Examples
215
+ #
216
+ # temporary_exceptions
217
+ # # => {PG::TRDeadlockDetected => 20, Net::OpenTimeout => 123}
218
+ #
219
+ # Returns Hash.
220
+ def temporary_exceptions
221
+ return @temporary_exceptions if defined?(@temporary_exceptions)
222
+
223
+ return {} unless self['resque.temporary_exceptions']
224
+
225
+ @temporary_exceptions = self['resque.temporary_exceptions'].each_with_object({}) do |(key, value), result|
226
+ result[key.constantize] = value
227
+ end
228
+ end
229
+
212
230
  private
213
231
  def load(path)
214
232
  if File.exists?(path)
@@ -1,5 +1,5 @@
1
1
  module Resque
2
2
  module Integration
3
- VERSION = '3.4.1'.freeze
3
+ VERSION = '3.5.0'.freeze
4
4
  end
5
5
  end
@@ -100,33 +100,34 @@ module Resque
100
100
 
101
101
  # Extend resque-retry.
102
102
  #
103
- # options - Hash
103
+ # options - Hash of retry options (default: {}):
104
+ # :limit - Integer max number of retry attempts (default: 2)
105
+ # :delay - Integer seconds between retry attempts (default: 60)
106
+ # :exceptions - Array or Hash of specific exceptions to retry (optional)
107
+ # :temporary - boolean retry on temporary exceptions list (default: false)
108
+ # :expire_retry_key_after - Integer expire of retry key in redis (default: 3200)
104
109
  #
105
- # :limit - Integer (default: 2)
106
- # :delay - Integer (default: 60)
107
- # :expire_retry_key_after - Integer (default: 3200), истечение ключа в секундах. Если
108
- #
109
- # t - среднее время выполнения одного джоба
110
- # n - текущее кол-во джобов в очереди
111
- # k - кол-во воркеров
112
- #
113
- # то expire_retry_key_after >= t * n / k
114
- #
115
- # Иначе ключ истечет, прежде чем джоб отработает.
116
- #
117
- #
118
- # Returns nothing
110
+ # Returns nothing.
119
111
  def retrys(options = {})
120
- if unique?
121
- raise '`retrys` should be declared higher in code than `unique`'
122
- end
112
+ raise '`retries` should be declared higher in code than `unique`' if unique?
123
113
 
124
114
  extend Resque::Plugins::Retry
125
115
 
126
116
  @retry_limit = options.fetch(:limit, 2)
127
117
  @retry_delay = options.fetch(:delay, 60)
118
+
119
+ @retry_exceptions = options[:exceptions] if options.key? :exceptions
120
+
121
+ if options[:temporary]
122
+ @retry_exceptions = @retry_exceptions && @retry_exceptions.dup || {}
123
+ @retry_exceptions = @retry_exceptions.product([@retry_delay]).to_h if @retry_exceptions.is_a? Array
124
+
125
+ @retry_exceptions.reverse_merge!(Resque.config.temporary_exceptions)
126
+ end
127
+
128
128
  @expire_retry_key_after = options.fetch(:expire_retry_key_after, 1.hour.seconds)
129
129
  end
130
+ alias retries retrys
130
131
 
131
132
  # Mark Job as ordered
132
133
  def ordered(options = {})
@@ -0,0 +1,10 @@
1
+ class RetriesArgumentErrorJob
2
+ include Resque::Integration
3
+
4
+ retries temporary: true, exceptions: [ArgumentError]
5
+ queue :test_retries
6
+
7
+ def self.execute
8
+ DummyForRetriesService.call
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class RetriesJob
2
+ include Resque::Integration
3
+
4
+ retries
5
+ queue :test_retries
6
+
7
+ def self.execute
8
+ DummyForRetriesService.call
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class RetriesStandardErrorJob
2
+ include Resque::Integration
3
+
4
+ retries temporary: true, exceptions: [StandardError]
5
+ queue :test_retries
6
+
7
+ def self.execute
8
+ DummyForRetriesService.call
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class DummyForRetriesService
2
+ def self.call
3
+ raise StandardError.new('test')
4
+ end
5
+ end
@@ -54,6 +54,18 @@ describe Resque::Integration::Configuration do
54
54
  it { expect(config.run_at_exit_hooks?).to be_falsey }
55
55
  end
56
56
  end
57
+
58
+ describe '#temporary_exceptions' do
59
+ context 'when default' do
60
+ it { expect(config.temporary_exceptions).to eq({}) }
61
+ end
62
+
63
+ context 'when defined' do
64
+ let(:config_yaml) { {'resque' => {'temporary_exceptions' => {'StandardError' => 12}}} }
65
+
66
+ it { expect(config.temporary_exceptions).to eq(StandardError => 12) }
67
+ end
68
+ end
57
69
  end
58
70
 
59
71
  describe Resque::Integration::Configuration::Notifier do
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  require 'spec_helper'
3
2
 
4
3
  RSpec.describe Resque::Integration do
@@ -102,4 +101,35 @@ RSpec.describe Resque::Integration do
102
101
  end
103
102
  end
104
103
  end
104
+
105
+ describe 'retries' do
106
+ context 'with default params' do
107
+ let(:job) { Resque::Job.new(:test_retries, 'class' => 'RetriesJob', 'args' => ['meta']) }
108
+
109
+ it do
110
+ expect { job.perform }.to raise_error StandardError
111
+ expect(Resque.delayed_queue_schedule_size).to eq 1
112
+ end
113
+ end
114
+
115
+ context 'with custom params' do
116
+ context 'with StandardError in exceptions' do
117
+ let(:job) { Resque::Job.new(:test_retries, 'class' => 'RetriesStandardErrorJob', 'args' => ['meta']) }
118
+
119
+ it do
120
+ expect { job.perform }.to raise_error StandardError
121
+ expect(Resque.delayed_queue_schedule_size).to eq 1
122
+ end
123
+ end
124
+
125
+ context 'with ArgumentError in exceptions' do
126
+ let(:job) { Resque::Job.new(:test_retries, 'class' => 'RetriesArgumentErrorJob', 'args' => ['meta']) }
127
+
128
+ it do
129
+ expect { job.perform }.to raise_error StandardError
130
+ expect(Resque.delayed_queue_schedule_size).to eq 0
131
+ end
132
+ end
133
+ end
134
+ end
105
135
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-integration
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.1
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexei Mikhailov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-22 00:00:00.000000000 Z
12
+ date: 2018-09-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: resque
@@ -349,6 +349,10 @@ files:
349
349
  - lib/resque/integration/version.rb
350
350
  - resque-integration.gemspec
351
351
  - spec/fixtures/resque_queues.yml
352
+ - spec/internal/app/jobs/retries_argument_error_job.rb
353
+ - spec/internal/app/jobs/retries_job.rb
354
+ - spec/internal/app/jobs/retries_standard_error_job.rb
355
+ - spec/internal/app/services/dummy_for_retries_service.rb
352
356
  - spec/resque/controllers/jobs_controller_spec.rb
353
357
  - spec/resque/integration/configuration_spec.rb
354
358
  - spec/resque/integration/continuous_spec.rb
@@ -389,6 +393,10 @@ specification_version: 4
389
393
  summary: Seamless integration of resque with resque-progress and resque-lock
390
394
  test_files:
391
395
  - spec/fixtures/resque_queues.yml
396
+ - spec/internal/app/jobs/retries_argument_error_job.rb
397
+ - spec/internal/app/jobs/retries_job.rb
398
+ - spec/internal/app/jobs/retries_standard_error_job.rb
399
+ - spec/internal/app/services/dummy_for_retries_service.rb
392
400
  - spec/resque/controllers/jobs_controller_spec.rb
393
401
  - spec/resque/integration/configuration_spec.rb
394
402
  - spec/resque/integration/continuous_spec.rb