sidekiq 6.4.2 → 6.5.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sidekiq might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Changes.md +35 -0
- data/bin/sidekiqload +15 -3
- data/lib/sidekiq/api.rb +160 -32
- data/lib/sidekiq/cli.rb +34 -32
- data/lib/sidekiq/client.rb +4 -4
- data/lib/sidekiq/component.rb +65 -0
- data/lib/sidekiq/delay.rb +1 -1
- data/lib/sidekiq/fetch.rb +16 -14
- data/lib/sidekiq/job_retry.rb +50 -34
- data/lib/sidekiq/job_util.rb +7 -3
- data/lib/sidekiq/launcher.rb +22 -19
- data/lib/sidekiq/logger.rb +1 -1
- data/lib/sidekiq/manager.rb +23 -20
- data/lib/sidekiq/metrics/deploy.rb +47 -0
- data/lib/sidekiq/metrics/query.rb +124 -0
- data/lib/sidekiq/metrics/shared.rb +94 -0
- data/lib/sidekiq/metrics/tracking.rb +134 -0
- data/lib/sidekiq/middleware/chain.rb +82 -38
- data/lib/sidekiq/middleware/current_attributes.rb +10 -4
- data/lib/sidekiq/middleware/i18n.rb +2 -0
- data/lib/sidekiq/middleware/modules.rb +21 -0
- data/lib/sidekiq/paginator.rb +2 -2
- data/lib/sidekiq/processor.rb +13 -13
- data/lib/sidekiq/rails.rb +5 -5
- data/lib/sidekiq/redis_client_adapter.rb +154 -0
- data/lib/sidekiq/redis_connection.rb +80 -47
- data/lib/sidekiq/ring_buffer.rb +29 -0
- data/lib/sidekiq/scheduled.rb +11 -10
- data/lib/sidekiq/testing.rb +1 -1
- data/lib/sidekiq/transaction_aware_client.rb +45 -0
- data/lib/sidekiq/version.rb +1 -1
- data/lib/sidekiq/web/application.rb +13 -0
- data/lib/sidekiq/web/helpers.rb +25 -2
- data/lib/sidekiq/web.rb +4 -0
- data/lib/sidekiq/worker.rb +2 -1
- data/lib/sidekiq.rb +87 -18
- data/sidekiq.gemspec +1 -1
- data/web/assets/javascripts/application.js +1 -1
- data/web/assets/javascripts/dashboard.js +0 -17
- data/web/assets/javascripts/graph.js +16 -0
- data/web/locales/en.yml +4 -0
- data/web/locales/pt-br.yml +27 -9
- data/web/views/_nav.erb +1 -1
- data/web/views/busy.erb +1 -1
- data/web/views/dashboard.erb +1 -0
- data/web/views/metrics.erb +59 -0
- data/web/views/metrics_for_job.erb +92 -0
- data/web/views/queue.erb +5 -1
- metadata +16 -6
- data/lib/sidekiq/exception_handler.rb +0 -27
- data/lib/sidekiq/util.rb +0 -108
data/lib/sidekiq/cli.rb
CHANGED
@@ -9,18 +9,23 @@ require "erb"
|
|
9
9
|
require "fileutils"
|
10
10
|
|
11
11
|
require "sidekiq"
|
12
|
+
require "sidekiq/component"
|
12
13
|
require "sidekiq/launcher"
|
13
|
-
require "sidekiq/util"
|
14
14
|
|
15
|
-
module Sidekiq
|
15
|
+
module Sidekiq # :nodoc:
|
16
16
|
class CLI
|
17
|
-
include
|
17
|
+
include Sidekiq::Component
|
18
18
|
include Singleton unless $TESTING
|
19
19
|
|
20
20
|
attr_accessor :launcher
|
21
21
|
attr_accessor :environment
|
22
|
+
attr_accessor :config
|
22
23
|
|
23
24
|
def parse(args = ARGV.dup)
|
25
|
+
@config = Sidekiq
|
26
|
+
@config[:error_handlers].clear
|
27
|
+
@config[:error_handlers] << @config.method(:default_error_handler)
|
28
|
+
|
24
29
|
setup_options(args)
|
25
30
|
initialize_logger
|
26
31
|
validate!
|
@@ -36,7 +41,7 @@ module Sidekiq
|
|
36
41
|
def run(boot_app: true)
|
37
42
|
boot_application if boot_app
|
38
43
|
|
39
|
-
if environment == "development" && $stdout.tty? &&
|
44
|
+
if environment == "development" && $stdout.tty? && @config.log_formatter.is_a?(Sidekiq::Logger::Formatters::Pretty)
|
40
45
|
print_banner
|
41
46
|
end
|
42
47
|
logger.info "Booted Rails #{::Rails.version} application in #{environment} environment" if rails_app?
|
@@ -67,7 +72,7 @@ module Sidekiq
|
|
67
72
|
|
68
73
|
# touch the connection pool so it is created before we
|
69
74
|
# fire startup and start multithreading.
|
70
|
-
info =
|
75
|
+
info = @config.redis_info
|
71
76
|
ver = info["redis_version"]
|
72
77
|
raise "You are connecting to Redis v#{ver}, Sidekiq requires Redis v4.0.0 or greater" if ver < "4"
|
73
78
|
|
@@ -85,22 +90,22 @@ module Sidekiq
|
|
85
90
|
|
86
91
|
# Since the user can pass us a connection pool explicitly in the initializer, we
|
87
92
|
# need to verify the size is large enough or else Sidekiq's performance is dramatically slowed.
|
88
|
-
cursize =
|
89
|
-
needed =
|
93
|
+
cursize = @config.redis_pool.size
|
94
|
+
needed = @config[:concurrency] + 2
|
90
95
|
raise "Your pool of #{cursize} Redis connections is too small, please increase the size to at least #{needed}" if cursize < needed
|
91
96
|
|
92
97
|
# cache process identity
|
93
|
-
|
98
|
+
@config[:identity] = identity
|
94
99
|
|
95
100
|
# Touch middleware so it isn't lazy loaded by multiple threads, #3043
|
96
|
-
|
101
|
+
@config.server_middleware
|
97
102
|
|
98
103
|
# Before this point, the process is initializing with just the main thread.
|
99
104
|
# Starting here the process will now have multiple threads running.
|
100
105
|
fire_event(:startup, reverse: false, reraise: true)
|
101
106
|
|
102
|
-
logger.debug { "Client Middleware: #{
|
103
|
-
logger.debug { "Server Middleware: #{
|
107
|
+
logger.debug { "Client Middleware: #{@config.client_middleware.map(&:klass).join(", ")}" }
|
108
|
+
logger.debug { "Server Middleware: #{@config.server_middleware.map(&:klass).join(", ")}" }
|
104
109
|
|
105
110
|
launch(self_read)
|
106
111
|
end
|
@@ -110,7 +115,7 @@ module Sidekiq
|
|
110
115
|
logger.info "Starting processing, hit Ctrl-C to stop"
|
111
116
|
end
|
112
117
|
|
113
|
-
@launcher = Sidekiq::Launcher.new(
|
118
|
+
@launcher = Sidekiq::Launcher.new(@config)
|
114
119
|
|
115
120
|
begin
|
116
121
|
launcher.run
|
@@ -173,25 +178,25 @@ module Sidekiq
|
|
173
178
|
# Heroku sends TERM and then waits 30 seconds for process to exit.
|
174
179
|
"TERM" => ->(cli) { raise Interrupt },
|
175
180
|
"TSTP" => ->(cli) {
|
176
|
-
|
181
|
+
cli.logger.info "Received TSTP, no longer accepting new work"
|
177
182
|
cli.launcher.quiet
|
178
183
|
},
|
179
184
|
"TTIN" => ->(cli) {
|
180
185
|
Thread.list.each do |thread|
|
181
|
-
|
186
|
+
cli.logger.warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread.name}"
|
182
187
|
if thread.backtrace
|
183
|
-
|
188
|
+
cli.logger.warn thread.backtrace.join("\n")
|
184
189
|
else
|
185
|
-
|
190
|
+
cli.logger.warn "<no backtrace available>"
|
186
191
|
end
|
187
192
|
end
|
188
193
|
}
|
189
194
|
}
|
190
|
-
UNHANDLED_SIGNAL_HANDLER = ->(cli) {
|
195
|
+
UNHANDLED_SIGNAL_HANDLER = ->(cli) { cli.logger.info "No signal handler registered, ignoring" }
|
191
196
|
SIGNAL_HANDLERS.default = UNHANDLED_SIGNAL_HANDLER
|
192
197
|
|
193
198
|
def handle_signal(sig)
|
194
|
-
|
199
|
+
logger.debug "Got #{sig} signal"
|
195
200
|
SIGNAL_HANDLERS[sig].call(self)
|
196
201
|
end
|
197
202
|
|
@@ -237,7 +242,7 @@ module Sidekiq
|
|
237
242
|
config_dir = if File.directory?(opts[:require].to_s)
|
238
243
|
File.join(opts[:require], "config")
|
239
244
|
else
|
240
|
-
File.join(
|
245
|
+
File.join(@config[:require], "config")
|
241
246
|
end
|
242
247
|
|
243
248
|
%w[sidekiq.yml sidekiq.yml.erb].each do |config_file|
|
@@ -254,27 +259,23 @@ module Sidekiq
|
|
254
259
|
opts[:concurrency] = Integer(ENV["RAILS_MAX_THREADS"]) if opts[:concurrency].nil? && ENV["RAILS_MAX_THREADS"]
|
255
260
|
|
256
261
|
# merge with defaults
|
257
|
-
|
258
|
-
end
|
259
|
-
|
260
|
-
def options
|
261
|
-
Sidekiq.options
|
262
|
+
@config.merge!(opts)
|
262
263
|
end
|
263
264
|
|
264
265
|
def boot_application
|
265
266
|
ENV["RACK_ENV"] = ENV["RAILS_ENV"] = environment
|
266
267
|
|
267
|
-
if File.directory?(
|
268
|
+
if File.directory?(@config[:require])
|
268
269
|
require "rails"
|
269
270
|
if ::Rails::VERSION::MAJOR < 5
|
270
271
|
raise "Sidekiq no longer supports this version of Rails"
|
271
272
|
else
|
272
273
|
require "sidekiq/rails"
|
273
|
-
require File.expand_path("#{
|
274
|
+
require File.expand_path("#{@config[:require]}/config/environment.rb")
|
274
275
|
end
|
275
|
-
|
276
|
+
@config[:tag] ||= default_tag
|
276
277
|
else
|
277
|
-
require
|
278
|
+
require @config[:require]
|
278
279
|
end
|
279
280
|
end
|
280
281
|
|
@@ -291,8 +292,8 @@ module Sidekiq
|
|
291
292
|
end
|
292
293
|
|
293
294
|
def validate!
|
294
|
-
if !File.exist?(
|
295
|
-
(File.directory?(
|
295
|
+
if !File.exist?(@config[:require]) ||
|
296
|
+
(File.directory?(@config[:require]) && !File.exist?("#{@config[:require]}/config/application.rb"))
|
296
297
|
logger.info "=================================================================="
|
297
298
|
logger.info " Please point Sidekiq to a Rails application or a Ruby file "
|
298
299
|
logger.info " to load your job classes with -r [DIR|FILE]."
|
@@ -302,7 +303,7 @@ module Sidekiq
|
|
302
303
|
end
|
303
304
|
|
304
305
|
[:concurrency, :timeout].each do |opt|
|
305
|
-
raise ArgumentError, "#{opt}: #{
|
306
|
+
raise ArgumentError, "#{opt}: #{@config[opt]} is not a valid value" if @config[opt].to_i <= 0
|
306
307
|
end
|
307
308
|
end
|
308
309
|
|
@@ -376,7 +377,7 @@ module Sidekiq
|
|
376
377
|
end
|
377
378
|
|
378
379
|
def initialize_logger
|
379
|
-
|
380
|
+
@config.logger.level = ::Logger::DEBUG if @config[:verbose]
|
380
381
|
end
|
381
382
|
|
382
383
|
def parse_config(path)
|
@@ -425,3 +426,4 @@ module Sidekiq
|
|
425
426
|
end
|
426
427
|
|
427
428
|
require "sidekiq/systemd"
|
429
|
+
require "sidekiq/metrics/tracking"
|
data/lib/sidekiq/client.rb
CHANGED
@@ -71,7 +71,7 @@ module Sidekiq
|
|
71
71
|
#
|
72
72
|
def push(item)
|
73
73
|
normed = normalize_item(item)
|
74
|
-
payload = middleware.invoke(
|
74
|
+
payload = middleware.invoke(item["class"], normed, normed["queue"], @redis_pool) do
|
75
75
|
normed
|
76
76
|
end
|
77
77
|
if payload
|
@@ -110,7 +110,7 @@ module Sidekiq
|
|
110
110
|
payloads = args.map.with_index { |job_args, index|
|
111
111
|
copy = normed.merge("args" => job_args, "jid" => SecureRandom.hex(12))
|
112
112
|
copy["at"] = (at.is_a?(Array) ? at[index] : at) if at
|
113
|
-
result = middleware.invoke(
|
113
|
+
result = middleware.invoke(items["class"], copy, copy["queue"], @redis_pool) do
|
114
114
|
verify_json(copy)
|
115
115
|
copy
|
116
116
|
end
|
@@ -201,7 +201,7 @@ module Sidekiq
|
|
201
201
|
conn.pipelined do |pipeline|
|
202
202
|
atomic_push(pipeline, payloads)
|
203
203
|
end
|
204
|
-
rescue
|
204
|
+
rescue RedisConnection.adapter::BaseError => ex
|
205
205
|
# 2550 Failover can cause the server to become a replica, need
|
206
206
|
# to disconnect and reopen the socket to get back to the primary.
|
207
207
|
# 4495 Use the same logic if we have a "Not enough replicas" error from the primary
|
@@ -220,7 +220,7 @@ module Sidekiq
|
|
220
220
|
|
221
221
|
def atomic_push(conn, payloads)
|
222
222
|
if payloads.first.key?("at")
|
223
|
-
conn.zadd("schedule", payloads.
|
223
|
+
conn.zadd("schedule", payloads.flat_map { |hash|
|
224
224
|
at = hash.delete("at").to_s
|
225
225
|
[at, Sidekiq.dump_json(hash)]
|
226
226
|
})
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
##
|
3
|
+
# Sidekiq::Component assumes a config instance is available at @config
|
4
|
+
module Component # :nodoc:
|
5
|
+
attr_reader :config
|
6
|
+
|
7
|
+
def watchdog(last_words)
|
8
|
+
yield
|
9
|
+
rescue Exception => ex
|
10
|
+
handle_exception(ex, {context: last_words})
|
11
|
+
raise ex
|
12
|
+
end
|
13
|
+
|
14
|
+
def safe_thread(name, &block)
|
15
|
+
Thread.new do
|
16
|
+
Thread.current.name = name
|
17
|
+
watchdog(name, &block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def logger
|
22
|
+
config.logger
|
23
|
+
end
|
24
|
+
|
25
|
+
def redis(&block)
|
26
|
+
config.redis(&block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def tid
|
30
|
+
Thread.current["sidekiq_tid"] ||= (Thread.current.object_id ^ ::Process.pid).to_s(36)
|
31
|
+
end
|
32
|
+
|
33
|
+
def hostname
|
34
|
+
ENV["DYNO"] || Socket.gethostname
|
35
|
+
end
|
36
|
+
|
37
|
+
def process_nonce
|
38
|
+
@@process_nonce ||= SecureRandom.hex(6)
|
39
|
+
end
|
40
|
+
|
41
|
+
def identity
|
42
|
+
@@identity ||= "#{hostname}:#{::Process.pid}:#{process_nonce}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def handle_exception(ex, ctx = {})
|
46
|
+
config.handle_exception(ex, ctx)
|
47
|
+
end
|
48
|
+
|
49
|
+
def fire_event(event, options = {})
|
50
|
+
oneshot = options.fetch(:oneshot, true)
|
51
|
+
reverse = options[:reverse]
|
52
|
+
reraise = options[:reraise]
|
53
|
+
|
54
|
+
arr = config[:lifecycle_events][event]
|
55
|
+
arr.reverse! if reverse
|
56
|
+
arr.each do |block|
|
57
|
+
block.call
|
58
|
+
rescue => ex
|
59
|
+
handle_exception(ex, {context: "Exception during Sidekiq lifecycle event.", event: event})
|
60
|
+
raise ex if reraise
|
61
|
+
end
|
62
|
+
arr.clear if oneshot # once we've fired an event, we never fire it again
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/sidekiq/delay.rb
CHANGED
data/lib/sidekiq/fetch.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "sidekiq"
|
4
|
+
require "sidekiq/component"
|
4
5
|
|
5
|
-
module Sidekiq
|
6
|
+
module Sidekiq # :nodoc:
|
6
7
|
class BasicFetch
|
8
|
+
include Sidekiq::Component
|
7
9
|
# We want the fetch operation to timeout every few seconds so the thread
|
8
10
|
# can check if the process is shutting down.
|
9
11
|
TIMEOUT = 2
|
10
12
|
|
11
|
-
UnitOfWork = Struct.new(:queue, :job) {
|
13
|
+
UnitOfWork = Struct.new(:queue, :job, :config) {
|
12
14
|
def acknowledge
|
13
15
|
# nothing to do
|
14
16
|
end
|
@@ -18,17 +20,17 @@ module Sidekiq
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def requeue
|
21
|
-
|
23
|
+
config.redis do |conn|
|
22
24
|
conn.rpush(queue, job)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
}
|
26
28
|
|
27
|
-
def initialize(
|
28
|
-
raise ArgumentError, "missing queue list" unless
|
29
|
-
@
|
30
|
-
@strictly_ordered_queues = !!@
|
31
|
-
@queues = @
|
29
|
+
def initialize(config)
|
30
|
+
raise ArgumentError, "missing queue list" unless config[:queues]
|
31
|
+
@config = config
|
32
|
+
@strictly_ordered_queues = !!@config[:strict]
|
33
|
+
@queues = @config[:queues].map { |q| "queue:#{q}" }
|
32
34
|
if @strictly_ordered_queues
|
33
35
|
@queues.uniq!
|
34
36
|
@queues << TIMEOUT
|
@@ -44,30 +46,30 @@ module Sidekiq
|
|
44
46
|
return nil
|
45
47
|
end
|
46
48
|
|
47
|
-
|
48
|
-
UnitOfWork.new(
|
49
|
+
queue, job = redis { |conn| conn.brpop(*qs) }
|
50
|
+
UnitOfWork.new(queue, job, config) if queue
|
49
51
|
end
|
50
52
|
|
51
53
|
def bulk_requeue(inprogress, options)
|
52
54
|
return if inprogress.empty?
|
53
55
|
|
54
|
-
|
56
|
+
logger.debug { "Re-queueing terminated jobs" }
|
55
57
|
jobs_to_requeue = {}
|
56
58
|
inprogress.each do |unit_of_work|
|
57
59
|
jobs_to_requeue[unit_of_work.queue] ||= []
|
58
60
|
jobs_to_requeue[unit_of_work.queue] << unit_of_work.job
|
59
61
|
end
|
60
62
|
|
61
|
-
|
63
|
+
redis do |conn|
|
62
64
|
conn.pipelined do |pipeline|
|
63
65
|
jobs_to_requeue.each do |queue, jobs|
|
64
66
|
pipeline.rpush(queue, jobs)
|
65
67
|
end
|
66
68
|
end
|
67
69
|
end
|
68
|
-
|
70
|
+
logger.info("Pushed #{inprogress.size} jobs back to Redis")
|
69
71
|
rescue => ex
|
70
|
-
|
72
|
+
logger.warn("Failed to requeue #{inprogress.size} jobs: #{ex.message}")
|
71
73
|
end
|
72
74
|
|
73
75
|
# Creating the Redis#brpop command takes into account any
|
data/lib/sidekiq/job_retry.rb
CHANGED
@@ -66,12 +66,13 @@ module Sidekiq
|
|
66
66
|
|
67
67
|
class Skip < Handled; end
|
68
68
|
|
69
|
-
include Sidekiq::
|
69
|
+
include Sidekiq::Component
|
70
70
|
|
71
71
|
DEFAULT_MAX_RETRY_ATTEMPTS = 25
|
72
72
|
|
73
|
-
def initialize(options
|
74
|
-
@
|
73
|
+
def initialize(options)
|
74
|
+
@config = options
|
75
|
+
@max_retries = @config[:max_retries] || DEFAULT_MAX_RETRY_ATTEMPTS
|
75
76
|
end
|
76
77
|
|
77
78
|
# The global retry handler requires only the barest of data.
|
@@ -90,7 +91,7 @@ module Sidekiq
|
|
90
91
|
|
91
92
|
msg = Sidekiq.load_json(jobstr)
|
92
93
|
if msg["retry"]
|
93
|
-
|
94
|
+
process_retry(nil, msg, queue, e)
|
94
95
|
else
|
95
96
|
Sidekiq.death_handlers.each do |handler|
|
96
97
|
handler.call(msg, e)
|
@@ -127,7 +128,7 @@ module Sidekiq
|
|
127
128
|
end
|
128
129
|
|
129
130
|
raise e unless msg["retry"]
|
130
|
-
|
131
|
+
process_retry(jobinst, msg, queue, e)
|
131
132
|
# We've handled this error associated with this job, don't
|
132
133
|
# need to handle it at the global level
|
133
134
|
raise Skip
|
@@ -138,7 +139,7 @@ module Sidekiq
|
|
138
139
|
# Note that +jobinst+ can be nil here if an error is raised before we can
|
139
140
|
# instantiate the job instance. All access must be guarded and
|
140
141
|
# best effort.
|
141
|
-
def
|
142
|
+
def process_retry(jobinst, msg, queue, exception)
|
142
143
|
max_retry_attempts = retry_attempts_from(msg["retry"], @max_retries)
|
143
144
|
|
144
145
|
msg["queue"] = (msg["retry_queue"] || queue)
|
@@ -169,19 +170,50 @@ module Sidekiq
|
|
169
170
|
msg["error_backtrace"] = compress_backtrace(lines)
|
170
171
|
end
|
171
172
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
173
|
+
# Goodbye dear message, you (re)tried your best I'm sure.
|
174
|
+
return retries_exhausted(jobinst, msg, exception) if count >= max_retry_attempts
|
175
|
+
|
176
|
+
strategy, delay = delay_for(jobinst, count, exception)
|
177
|
+
case strategy
|
178
|
+
when :discard
|
179
|
+
return # poof!
|
180
|
+
when :kill
|
181
|
+
return retries_exhausted(jobinst, msg, exception)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Logging here can break retries if the logging device raises ENOSPC #3979
|
185
|
+
# logger.debug { "Failure! Retry #{count} in #{delay} seconds" }
|
186
|
+
jitter = rand(10) * (count + 1)
|
187
|
+
retry_at = Time.now.to_f + delay + jitter
|
188
|
+
payload = Sidekiq.dump_json(msg)
|
189
|
+
redis do |conn|
|
190
|
+
conn.zadd("retry", retry_at.to_s, payload)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
# returns (strategy, seconds)
|
195
|
+
def delay_for(jobinst, count, exception)
|
196
|
+
rv = begin
|
197
|
+
# sidekiq_retry_in can return two different things:
|
198
|
+
# 1. When to retry next, as an integer of seconds
|
199
|
+
# 2. A symbol which re-routes the job elsewhere, e.g. :discard, :kill, :default
|
200
|
+
jobinst&.sidekiq_retry_in_block&.call(count, exception)
|
201
|
+
rescue Exception => e
|
202
|
+
handle_exception(e, {context: "Failure scheduling retry using the defined `sidekiq_retry_in` in #{jobinst.class.name}, falling back to default"})
|
203
|
+
nil
|
204
|
+
end
|
205
|
+
|
206
|
+
delay = if Integer === rv && rv > 0
|
207
|
+
rv
|
208
|
+
elsif rv == :discard
|
209
|
+
return [:discard, nil] # do nothing, job goes poof
|
210
|
+
elsif rv == :kill
|
211
|
+
return [:kill, nil]
|
181
212
|
else
|
182
|
-
|
183
|
-
retries_exhausted(jobinst, msg, exception)
|
213
|
+
(count**4) + 15
|
184
214
|
end
|
215
|
+
|
216
|
+
[:default, delay]
|
185
217
|
end
|
186
218
|
|
187
219
|
def retries_exhausted(jobinst, msg, exception)
|
@@ -194,7 +226,7 @@ module Sidekiq
|
|
194
226
|
|
195
227
|
send_to_morgue(msg) unless msg["dead"] == false
|
196
228
|
|
197
|
-
|
229
|
+
config.death_handlers.each do |handler|
|
198
230
|
handler.call(msg, exception)
|
199
231
|
rescue => e
|
200
232
|
handle_exception(e, {context: "Error calling death handler", job: msg})
|
@@ -215,22 +247,6 @@ module Sidekiq
|
|
215
247
|
end
|
216
248
|
end
|
217
249
|
|
218
|
-
def delay_for(jobinst, count, exception)
|
219
|
-
jitter = rand(10) * (count + 1)
|
220
|
-
if jobinst&.sidekiq_retry_in_block
|
221
|
-
custom_retry_in = retry_in(jobinst, count, exception).to_i
|
222
|
-
return custom_retry_in + jitter if custom_retry_in > 0
|
223
|
-
end
|
224
|
-
(count**4) + 15 + jitter
|
225
|
-
end
|
226
|
-
|
227
|
-
def retry_in(jobinst, count, exception)
|
228
|
-
jobinst.sidekiq_retry_in_block.call(count, exception)
|
229
|
-
rescue Exception => e
|
230
|
-
handle_exception(e, {context: "Failure scheduling retry using the defined `sidekiq_retry_in` in #{jobinst.class.name}, falling back to default"})
|
231
|
-
nil
|
232
|
-
end
|
233
|
-
|
234
250
|
def exception_caused_by_shutdown?(e, checked_causes = [])
|
235
251
|
return false unless e.cause
|
236
252
|
|
data/lib/sidekiq/job_util.rb
CHANGED
@@ -4,7 +4,8 @@ require "time"
|
|
4
4
|
module Sidekiq
|
5
5
|
module JobUtil
|
6
6
|
# These functions encapsulate various job utilities.
|
7
|
-
|
7
|
+
|
8
|
+
TRANSIENT_ATTRIBUTES = %w[]
|
8
9
|
|
9
10
|
def validate(item)
|
10
11
|
raise(ArgumentError, "Job must be a Hash with 'class' and 'args' keys: `#{item}`") unless item.is_a?(Hash) && item.key?("class") && item.key?("args")
|
@@ -16,13 +17,13 @@ module Sidekiq
|
|
16
17
|
|
17
18
|
def verify_json(item)
|
18
19
|
job_class = item["wrapped"] || item["class"]
|
19
|
-
if Sidekiq
|
20
|
+
if Sidekiq[:on_complex_arguments] == :raise
|
20
21
|
msg = <<~EOM
|
21
22
|
Job arguments to #{job_class} must be native JSON types, see https://github.com/mperham/sidekiq/wiki/Best-Practices.
|
22
23
|
To disable this error, remove `Sidekiq.strict_args!` from your initializer.
|
23
24
|
EOM
|
24
25
|
raise(ArgumentError, msg) unless json_safe?(item)
|
25
|
-
elsif Sidekiq
|
26
|
+
elsif Sidekiq[:on_complex_arguments] == :warn
|
26
27
|
Sidekiq.logger.warn <<~EOM unless json_safe?(item)
|
27
28
|
Job arguments to #{job_class} do not serialize to JSON safely. This will raise an error in
|
28
29
|
Sidekiq 7.0. See https://github.com/mperham/sidekiq/wiki/Best-Practices or raise an error today
|
@@ -42,6 +43,9 @@ module Sidekiq
|
|
42
43
|
|
43
44
|
raise(ArgumentError, "Job must include a valid queue name") if item["queue"].nil? || item["queue"] == ""
|
44
45
|
|
46
|
+
# remove job attributes which aren't necessary to persist into Redis
|
47
|
+
TRANSIENT_ATTRIBUTES.each { |key| item.delete(key) }
|
48
|
+
|
45
49
|
item["jid"] ||= SecureRandom.hex(12)
|
46
50
|
item["class"] = item["class"].to_s
|
47
51
|
item["queue"] = item["queue"].to_s
|