Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

polish default failure mode

  • Loading branch information...
commit 98144078e55018e2bb27376ff747e37b68bf613e 1 parent 121f82a
@mhfs authored
View
16 README.md
@@ -37,7 +37,7 @@ This is the default behavior but can be made explicit with:
class MyWorker
include Sidekiq::Worker
- sidekiq_options :failures => true
+ sidekiq_options :failures => true # or :all
def perform; end
end
@@ -67,12 +67,24 @@ You can also completely turn off failures tracking for a given worker as follows
class MyWorker
include Sidekiq::Worker
- sidekiq_options :failures => false
+ sidekiq_options :failures => false # or :off
def perform; end
end
```
+### Change the default mode
+
+You can also change the default of all your workers at once by setting the following server config:
+
+```ruby
+Sidekiq.configure_server do |config|
+ config.failures_default_mode = :off
+end
+```
+
+The valid modes are `:all`, `:exhausted`, `:off`, `true` or `false`.
+
## TODO
* Allow triggering retry of specific failed jobs via Web UI.
View
1  lib/sidekiq-failures.rb
@@ -1,2 +1 @@
require "sidekiq/failures"
-
View
19 lib/sidekiq/failures.rb 100755 → 100644
@@ -5,20 +5,27 @@
module Sidekiq
- SIDEKIQ_FAILURES_MODES = ['all', 'exhausted'].freeze
-
+ SIDEKIQ_FAILURES_MODES = [:all, :exhausted, :off].freeze
+
+ # Sets the default failure tracking mode.
+ #
+ # The value provided here will be the default behavior but can be overwritten
+ # per worker by using `sidekiq_options :failures => :mode`
+ #
+ # Defaults to :all
def self.failures_default_mode=(mode)
- unless SIDEKIQ_FAILURES_MODES.include?(mode.to_s)
+ unless SIDEKIQ_FAILURES_MODES.include?(mode.to_sym)
raise ArgumentError, "Sidekiq#failures_default_mode valid options: #{SIDEKIQ_FAILURES_MODES}"
end
- @failures_default_mode = mode
+
+ @failures_default_mode = mode.to_sym
end
+ # Fetches the default failure tracking mode.
def self.failures_default_mode
- @failures_default_mode || 'all'
+ @failures_default_mode || :all
end
-
module Failures
end
end
View
17 lib/sidekiq/failures/middleware.rb
@@ -27,18 +27,23 @@ def call(worker, msg, queue)
private
def skip_failure?
- msg['failures'] == false || not_exhausted?
+ failure_mode == :off || not_exhausted?
end
def not_exhausted?
- exhausted_mode? && !last_try?
+ failure_mode == :exhausted && !last_try?
end
- def exhausted_mode?
- if msg['failures']
- msg['failures'] == 'exhausted'
+ def failure_mode
+ case msg['failures'].to_s
+ when 'true', 'all'
+ :all
+ when 'false', 'off'
+ :off
+ when 'exhausted'
+ :exhausted
else
- Sidekiq.failures_default_mode.to_s == 'exhausted'
+ Sidekiq.failures_default_mode
end
end
View
2  test/middleware_test.rb 100755 → 100644
@@ -31,7 +31,7 @@ def perform(args)
end
it 'defaults failures_default_mode to all' do
- assert_equal 'all', Sidekiq.failures_default_mode
+ assert_equal :all, Sidekiq.failures_default_mode
end
it 'records all failures by default' do
View
0  test/test_helper.rb 100755 → 100644
File mode changed
Please sign in to comment.
Something went wrong with that request. Please try again.