activejob-retry 0.4.1 → 0.4.2

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: 4754f9d8dd24402b36af737064fb7cf2aa18f8bc
4
- data.tar.gz: 8eee87bdab72957f4d6b3f89ce94f7626c9ec1c7
3
+ metadata.gz: 5143405bed9e31a9105b3dc8d245f6e6d6b3f772
4
+ data.tar.gz: 029ae74c9cce202706f109991d67b07404cef2fc
5
5
  SHA512:
6
- metadata.gz: 143fd664736af53579dc7f63c3d59b8ad661d6cf209d58d1cb8158c44b4350298944daa8f1f4b2cbad6db7f84f52d80cd97ff76cb2b19125f38fd6404ad08b5a
7
- data.tar.gz: 925bce50297ad6b543769ad7f2257c89ef84ad02012cd70ca7eb59f447d1737ce73bcc45ff48e95be7b9879b20076b644b2476ad918795ba33545d286ca1d6fb
6
+ metadata.gz: a34362c6832bf49579a692d5219d808a46ccc2a89c9ebe6b02e8a53f8158091a20ce9e546697f3b78bc7c3a9294e84ec9cf0f8fb096f4d7c444e0f54f08f22d2
7
+ data.tar.gz: 5b3457112e0080fd42c0e9f288b89c8fd15cf473b6ce815a801be010949ed21a8555425503dd9b5b6cf08294384ee7383039e3c12fa31231ba3774395ac985c6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activejob-retry (0.4.1)
4
+ activejob-retry (0.4.2)
5
5
  activejob (>= 4.2)
6
6
  activesupport (>= 4.2)
7
7
 
data/README.md CHANGED
@@ -62,6 +62,49 @@ if the exception is not going to be retried, or has failed the final retry.
62
62
  | `retryable_exceptions` | `nil` | Same as for [constant_retry](#constant_retry-options).
63
63
  | `fatal_exceptions` | `[]` | Same as for [constant_retry](#constant_retry-options).
64
64
 
65
+ ## Supported backends
66
+
67
+ Any queue adapter which supports delayed enqueuing (i.e. the `enqueue_at`
68
+ method) will work with ActiveJob::Retry, however some queue backends have
69
+ automatic retry logic, which should be disabled. The cleanest way to do this is
70
+ to use a `rescue_from` in the jobs for which you're using ActiveJob::Retry, so
71
+ the queue backend never perceives the job as having failed. E.g.:
72
+
73
+ ```ruby
74
+ class MyJob < ActiveJob::Base
75
+ include ActiveJob::Retry
76
+
77
+ queue_as :some_job
78
+
79
+ constant_retry limit: 3, delay: 5, retryable_exceptions: [TimeoutError, NetworkError]
80
+
81
+ rescue_from(StandardError) { |error| MyErrorService.record(error) }
82
+
83
+ def perform
84
+ raise "Weird!"
85
+ end
86
+ end
87
+ ```
88
+
89
+ Since `rescue_from`s are only executed once all retries have been attempted,
90
+ this will send the recurring error to your error service (e.g. Airbrake,
91
+ Sentry), but will make it appear to the queue backend (e.g. Que, Sidekiq) as if
92
+ the job has succeeded.
93
+
94
+ An alternative is to alter the appropriate `JobWrapper` to alter the
95
+ configuration of the backend to disable retries globally. For Sidekiq this
96
+ would be:
97
+
98
+ ```ruby
99
+ # config/initializers/disable_sidekiq_retries.rb
100
+ ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper.sidekiq_options(retry: false)
101
+ ```
102
+
103
+ This has the advantages of moving failed jobs to the Dead Job Queue instead of
104
+ just executing the logic in the `rescue_from`, which makes manual re-enqueueing
105
+ easier. On the other hand it does disable Sidekiq's automatic retrying for all
106
+ ActiveJob jobs.
107
+
65
108
  Contributing
66
109
  ------------
67
110
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rake/testtask'
2
2
  require 'rubygems/package_task'
3
3
 
4
- ACTIVEJOB_ADAPTERS = %w(backburner delayed_job que resque)
4
+ ACTIVEJOB_ADAPTERS = %w(backburner delayed_job que resque sidekiq)
5
5
 
6
6
  task default: :test
7
7
  task test: 'test:default'
@@ -16,7 +16,6 @@ module ActiveJob
16
16
  'ActiveJob::QueueAdapters::InlineAdapter',
17
17
  'ActiveJob::QueueAdapters::QuAdapter',
18
18
  'ActiveJob::QueueAdapters::QueueClassicAdapter',
19
- 'ActiveJob::QueueAdapters::SidekiqAdapter',
20
19
  'ActiveJob::QueueAdapters::SneakersAdapter',
21
20
  'ActiveJob::QueueAdapters::SuckerPunchAdapter'
22
21
  ].freeze
@@ -1,5 +1,5 @@
1
1
  module ActiveJob
2
2
  module Retry
3
- VERSION = '0.4.1'
3
+ VERSION = '0.4.2'
4
4
  end
5
5
  end
@@ -8,6 +8,17 @@ GlobalID.app = 'aj'
8
8
 
9
9
  @adapter = ENV['AJADAPTER'] || 'resque'
10
10
 
11
+ def sidekiq?
12
+ @adapter == 'sidekiq'
13
+ end
14
+
15
+ def ruby_193?
16
+ RUBY_VERSION == '1.9.3' && RUBY_ENGINE != 'java'
17
+ end
18
+
19
+ # Sidekiq doesn't work with MRI 1.9.3
20
+ exit if sidekiq? && ruby_193?
21
+
11
22
  if ENV['AJ_INTEGRATION_TESTS']
12
23
  require 'support/integration/helper'
13
24
  else
@@ -45,8 +45,7 @@ class QueuingTest < ActiveSupport::TestCase
45
45
  end
46
46
 
47
47
  test 'should call rescue_from only when retries have run out' do
48
- TestJob.rescue_from(RuntimeError) { write_to_rescue_file }
49
- TestJob.perform_later(@id, false, true)
48
+ TestJob.perform_later(@id, false, true, true)
50
49
 
51
50
  wait_for_jobs_to_finish_for(2.seconds)
52
51
  assert_not job_executed
@@ -1,6 +1,17 @@
1
1
  require 'sidekiq/cli'
2
2
  require 'sidekiq/api'
3
3
 
4
+ module Sidekiq
5
+ class CLI
6
+ def boot_system_with_rescue
7
+ boot_system_without_rescue
8
+ rescue => e
9
+ raise unless /Application has been already initialized./ =~ e.message
10
+ end
11
+ alias_method_chain :boot_system, :rescue
12
+ end
13
+ end
14
+
4
15
  module SidekiqJobsManager
5
16
 
6
17
  def setup
@@ -17,7 +17,15 @@ class TestJob < ActiveJob::Base
17
17
  queue_as :integration_tests
18
18
  constant_retry limit: 2, delay: 3
19
19
 
20
- def perform(x, fail_first = false, fail_always = false)
20
+ rescue_from(RuntimeError) do |e|
21
+ if arguments[3]
22
+ write_to_rescue_file
23
+ else
24
+ raise e
25
+ end
26
+ end
27
+
28
+ def perform(x, fail_first = false, fail_always = false, rescue_file = false)
21
29
  raise "Failing first" if fail_first && retry_attempt == 1
22
30
  raise "Failing always" if fail_always
23
31
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejob-retry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac Seymour
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-18 00:00:00.000000000 Z
11
+ date: 2015-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob