sidekiq 6.1.2 → 6.5.6
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.
Potentially problematic release.
This version of sidekiq might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Changes.md +215 -2
- data/LICENSE +3 -3
- data/README.md +9 -4
- data/bin/sidekiq +3 -3
- data/bin/sidekiqload +70 -66
- data/bin/sidekiqmon +1 -1
- data/lib/generators/sidekiq/job_generator.rb +57 -0
- data/lib/generators/sidekiq/templates/{worker.rb.erb → job.rb.erb} +2 -2
- data/lib/generators/sidekiq/templates/{worker_spec.rb.erb → job_spec.rb.erb} +1 -1
- data/lib/generators/sidekiq/templates/{worker_test.rb.erb → job_test.rb.erb} +1 -1
- data/lib/sidekiq/api.rb +321 -145
- data/lib/sidekiq/cli.rb +73 -40
- data/lib/sidekiq/client.rb +48 -72
- data/lib/sidekiq/{util.rb → component.rb} +12 -14
- data/lib/sidekiq/delay.rb +3 -1
- data/lib/sidekiq/extensions/generic_proxy.rb +4 -2
- data/lib/sidekiq/fetch.rb +31 -20
- data/lib/sidekiq/job.rb +13 -0
- data/lib/sidekiq/job_logger.rb +16 -28
- data/lib/sidekiq/job_retry.rb +79 -59
- data/lib/sidekiq/job_util.rb +71 -0
- data/lib/sidekiq/launcher.rb +126 -65
- data/lib/sidekiq/logger.rb +11 -20
- data/lib/sidekiq/manager.rb +35 -34
- data/lib/sidekiq/metrics/deploy.rb +47 -0
- data/lib/sidekiq/metrics/query.rb +153 -0
- data/lib/sidekiq/metrics/shared.rb +94 -0
- data/lib/sidekiq/metrics/tracking.rb +134 -0
- data/lib/sidekiq/middleware/chain.rb +87 -41
- data/lib/sidekiq/middleware/current_attributes.rb +63 -0
- data/lib/sidekiq/middleware/i18n.rb +6 -4
- data/lib/sidekiq/middleware/modules.rb +21 -0
- data/lib/sidekiq/monitor.rb +1 -1
- data/lib/sidekiq/paginator.rb +8 -8
- data/lib/sidekiq/processor.rb +47 -41
- data/lib/sidekiq/rails.rb +22 -4
- data/lib/sidekiq/redis_client_adapter.rb +154 -0
- data/lib/sidekiq/redis_connection.rb +84 -55
- data/lib/sidekiq/ring_buffer.rb +29 -0
- data/lib/sidekiq/scheduled.rb +55 -25
- data/lib/sidekiq/testing/inline.rb +4 -4
- data/lib/sidekiq/testing.rb +38 -39
- data/lib/sidekiq/transaction_aware_client.rb +45 -0
- data/lib/sidekiq/version.rb +1 -1
- data/lib/sidekiq/web/action.rb +3 -3
- data/lib/sidekiq/web/application.rb +37 -13
- data/lib/sidekiq/web/csrf_protection.rb +30 -8
- data/lib/sidekiq/web/helpers.rb +60 -28
- data/lib/sidekiq/web/router.rb +4 -1
- data/lib/sidekiq/web.rb +38 -78
- data/lib/sidekiq/worker.rb +136 -13
- data/lib/sidekiq.rb +114 -31
- data/sidekiq.gemspec +12 -4
- data/web/assets/images/apple-touch-icon.png +0 -0
- data/web/assets/javascripts/application.js +113 -60
- data/web/assets/javascripts/chart.min.js +13 -0
- data/web/assets/javascripts/chartjs-plugin-annotation.min.js +7 -0
- data/web/assets/javascripts/dashboard.js +50 -67
- data/web/assets/javascripts/graph.js +16 -0
- data/web/assets/javascripts/metrics.js +262 -0
- data/web/assets/stylesheets/application-dark.css +36 -36
- data/web/assets/stylesheets/application-rtl.css +0 -4
- data/web/assets/stylesheets/application.css +82 -237
- data/web/locales/ar.yml +8 -2
- data/web/locales/el.yml +43 -19
- data/web/locales/en.yml +11 -1
- data/web/locales/es.yml +18 -2
- data/web/locales/fr.yml +8 -1
- data/web/locales/ja.yml +3 -0
- data/web/locales/lt.yml +1 -1
- data/web/locales/pt-br.yml +27 -9
- data/web/views/_footer.erb +1 -1
- data/web/views/_job_info.erb +1 -1
- data/web/views/_nav.erb +1 -1
- data/web/views/_poll_link.erb +2 -5
- data/web/views/_summary.erb +7 -7
- data/web/views/busy.erb +50 -19
- data/web/views/dashboard.erb +23 -14
- data/web/views/dead.erb +1 -1
- data/web/views/layout.erb +2 -1
- data/web/views/metrics.erb +69 -0
- data/web/views/metrics_for_job.erb +87 -0
- data/web/views/morgue.erb +6 -6
- data/web/views/queue.erb +15 -11
- data/web/views/queues.erb +3 -3
- data/web/views/retries.erb +7 -7
- data/web/views/retry.erb +1 -1
- data/web/views/scheduled.erb +1 -1
- metadata +43 -36
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -20
- data/.github/contributing.md +0 -32
- data/.github/workflows/ci.yml +0 -41
- data/.gitignore +0 -13
- data/.standard.yml +0 -20
- data/3.0-Upgrade.md +0 -70
- data/4.0-Upgrade.md +0 -53
- data/5.0-Upgrade.md +0 -56
- data/6.0-Upgrade.md +0 -72
- data/COMM-LICENSE +0 -97
- data/Ent-2.0-Upgrade.md +0 -37
- data/Ent-Changes.md +0 -281
- data/Gemfile +0 -24
- data/Gemfile.lock +0 -192
- data/Pro-2.0-Upgrade.md +0 -138
- data/Pro-3.0-Upgrade.md +0 -44
- data/Pro-4.0-Upgrade.md +0 -35
- data/Pro-5.0-Upgrade.md +0 -25
- data/Pro-Changes.md +0 -805
- data/Rakefile +0 -10
- data/code_of_conduct.md +0 -50
- data/lib/generators/sidekiq/worker_generator.rb +0 -57
- data/lib/sidekiq/exception_handler.rb +0 -27
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
|
23
|
+
|
24
|
+
def parse(args = ARGV.dup)
|
25
|
+
@config = Sidekiq
|
26
|
+
@config[:error_handlers].clear
|
27
|
+
@config[:error_handlers] << @config.method(:default_error_handler)
|
22
28
|
|
23
|
-
def parse(args = ARGV)
|
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?
|
@@ -46,7 +51,15 @@ module Sidekiq
|
|
46
51
|
# USR1 and USR2 don't work on the JVM
|
47
52
|
sigs << "USR2" if Sidekiq.pro? && !jruby?
|
48
53
|
sigs.each do |sig|
|
49
|
-
trap
|
54
|
+
old_handler = Signal.trap(sig) do
|
55
|
+
if old_handler.respond_to?(:call)
|
56
|
+
begin
|
57
|
+
old_handler.call
|
58
|
+
rescue Exception => exc
|
59
|
+
# signal handlers can't use Logger so puts only
|
60
|
+
puts ["Error in #{sig} handler", exc].inspect
|
61
|
+
end
|
62
|
+
end
|
50
63
|
self_write.puts(sig)
|
51
64
|
end
|
52
65
|
rescue ArgumentError
|
@@ -59,27 +72,40 @@ module Sidekiq
|
|
59
72
|
|
60
73
|
# touch the connection pool so it is created before we
|
61
74
|
# fire startup and start multithreading.
|
62
|
-
|
75
|
+
info = @config.redis_info
|
76
|
+
ver = info["redis_version"]
|
63
77
|
raise "You are connecting to Redis v#{ver}, Sidekiq requires Redis v4.0.0 or greater" if ver < "4"
|
64
78
|
|
79
|
+
maxmemory_policy = info["maxmemory_policy"]
|
80
|
+
if maxmemory_policy != "noeviction"
|
81
|
+
logger.warn <<~EOM
|
82
|
+
|
83
|
+
|
84
|
+
WARNING: Your Redis instance will evict Sidekiq data under heavy load.
|
85
|
+
The 'noeviction' maxmemory policy is recommended (current policy: '#{maxmemory_policy}').
|
86
|
+
See: https://github.com/mperham/sidekiq/wiki/Using-Redis#memory
|
87
|
+
|
88
|
+
EOM
|
89
|
+
end
|
90
|
+
|
65
91
|
# Since the user can pass us a connection pool explicitly in the initializer, we
|
66
92
|
# need to verify the size is large enough or else Sidekiq's performance is dramatically slowed.
|
67
|
-
cursize =
|
68
|
-
needed =
|
93
|
+
cursize = @config.redis_pool.size
|
94
|
+
needed = @config[:concurrency] + 2
|
69
95
|
raise "Your pool of #{cursize} Redis connections is too small, please increase the size to at least #{needed}" if cursize < needed
|
70
96
|
|
71
97
|
# cache process identity
|
72
|
-
|
98
|
+
@config[:identity] = identity
|
73
99
|
|
74
100
|
# Touch middleware so it isn't lazy loaded by multiple threads, #3043
|
75
|
-
|
101
|
+
@config.server_middleware
|
76
102
|
|
77
103
|
# Before this point, the process is initializing with just the main thread.
|
78
104
|
# Starting here the process will now have multiple threads running.
|
79
105
|
fire_event(:startup, reverse: false, reraise: true)
|
80
106
|
|
81
|
-
logger.debug { "Client Middleware: #{
|
82
|
-
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(", ")}" }
|
83
109
|
|
84
110
|
launch(self_read)
|
85
111
|
end
|
@@ -89,13 +115,13 @@ module Sidekiq
|
|
89
115
|
logger.info "Starting processing, hit Ctrl-C to stop"
|
90
116
|
end
|
91
117
|
|
92
|
-
@launcher = Sidekiq::Launcher.new(
|
118
|
+
@launcher = Sidekiq::Launcher.new(@config)
|
93
119
|
|
94
120
|
begin
|
95
121
|
launcher.run
|
96
122
|
|
97
|
-
while
|
98
|
-
signal =
|
123
|
+
while self_read.wait_readable
|
124
|
+
signal = self_read.gets.strip
|
99
125
|
handle_signal(signal)
|
100
126
|
end
|
101
127
|
rescue Interrupt
|
@@ -152,25 +178,25 @@ module Sidekiq
|
|
152
178
|
# Heroku sends TERM and then waits 30 seconds for process to exit.
|
153
179
|
"TERM" => ->(cli) { raise Interrupt },
|
154
180
|
"TSTP" => ->(cli) {
|
155
|
-
|
181
|
+
cli.logger.info "Received TSTP, no longer accepting new work"
|
156
182
|
cli.launcher.quiet
|
157
183
|
},
|
158
184
|
"TTIN" => ->(cli) {
|
159
185
|
Thread.list.each do |thread|
|
160
|
-
|
186
|
+
cli.logger.warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread.name}"
|
161
187
|
if thread.backtrace
|
162
|
-
|
188
|
+
cli.logger.warn thread.backtrace.join("\n")
|
163
189
|
else
|
164
|
-
|
190
|
+
cli.logger.warn "<no backtrace available>"
|
165
191
|
end
|
166
192
|
end
|
167
193
|
}
|
168
194
|
}
|
169
|
-
UNHANDLED_SIGNAL_HANDLER = ->(cli) {
|
195
|
+
UNHANDLED_SIGNAL_HANDLER = ->(cli) { cli.logger.info "No signal handler registered, ignoring" }
|
170
196
|
SIGNAL_HANDLERS.default = UNHANDLED_SIGNAL_HANDLER
|
171
197
|
|
172
198
|
def handle_signal(sig)
|
173
|
-
|
199
|
+
logger.debug "Got #{sig} signal"
|
174
200
|
SIGNAL_HANDLERS[sig].call(self)
|
175
201
|
end
|
176
202
|
|
@@ -216,7 +242,7 @@ module Sidekiq
|
|
216
242
|
config_dir = if File.directory?(opts[:require].to_s)
|
217
243
|
File.join(opts[:require], "config")
|
218
244
|
else
|
219
|
-
File.join(
|
245
|
+
File.join(@config[:require], "config")
|
220
246
|
end
|
221
247
|
|
222
248
|
%w[sidekiq.yml sidekiq.yml.erb].each do |config_file|
|
@@ -233,27 +259,23 @@ module Sidekiq
|
|
233
259
|
opts[:concurrency] = Integer(ENV["RAILS_MAX_THREADS"]) if opts[:concurrency].nil? && ENV["RAILS_MAX_THREADS"]
|
234
260
|
|
235
261
|
# merge with defaults
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
def options
|
240
|
-
Sidekiq.options
|
262
|
+
@config.merge!(opts)
|
241
263
|
end
|
242
264
|
|
243
265
|
def boot_application
|
244
266
|
ENV["RACK_ENV"] = ENV["RAILS_ENV"] = environment
|
245
267
|
|
246
|
-
if File.directory?(
|
268
|
+
if File.directory?(@config[:require])
|
247
269
|
require "rails"
|
248
270
|
if ::Rails::VERSION::MAJOR < 5
|
249
271
|
raise "Sidekiq no longer supports this version of Rails"
|
250
272
|
else
|
251
273
|
require "sidekiq/rails"
|
252
|
-
require File.expand_path("#{
|
274
|
+
require File.expand_path("#{@config[:require]}/config/environment.rb")
|
253
275
|
end
|
254
|
-
|
276
|
+
@config[:tag] ||= default_tag
|
255
277
|
else
|
256
|
-
require
|
278
|
+
require @config[:require]
|
257
279
|
end
|
258
280
|
end
|
259
281
|
|
@@ -270,18 +292,18 @@ module Sidekiq
|
|
270
292
|
end
|
271
293
|
|
272
294
|
def validate!
|
273
|
-
if !File.exist?(
|
274
|
-
(File.directory?(
|
295
|
+
if !File.exist?(@config[:require]) ||
|
296
|
+
(File.directory?(@config[:require]) && !File.exist?("#{@config[:require]}/config/application.rb"))
|
275
297
|
logger.info "=================================================================="
|
276
298
|
logger.info " Please point Sidekiq to a Rails application or a Ruby file "
|
277
|
-
logger.info " to load your
|
299
|
+
logger.info " to load your job classes with -r [DIR|FILE]."
|
278
300
|
logger.info "=================================================================="
|
279
301
|
logger.info @parser
|
280
302
|
die(1)
|
281
303
|
end
|
282
304
|
|
283
305
|
[:concurrency, :timeout].each do |opt|
|
284
|
-
raise ArgumentError, "#{opt}: #{
|
306
|
+
raise ArgumentError, "#{opt}: #{@config[opt]} is not a valid value" if @config[opt].to_i <= 0
|
285
307
|
end
|
286
308
|
end
|
287
309
|
|
@@ -315,7 +337,7 @@ module Sidekiq
|
|
315
337
|
parse_queue opts, queue, weight
|
316
338
|
end
|
317
339
|
|
318
|
-
o.on "-r", "--require [PATH|DIR]", "Location of Rails application with
|
340
|
+
o.on "-r", "--require [PATH|DIR]", "Location of Rails application with jobs or file to require" do |arg|
|
319
341
|
opts[:require] = arg
|
320
342
|
end
|
321
343
|
|
@@ -355,11 +377,13 @@ module Sidekiq
|
|
355
377
|
end
|
356
378
|
|
357
379
|
def initialize_logger
|
358
|
-
|
380
|
+
@config.logger.level = ::Logger::DEBUG if @config[:verbose]
|
359
381
|
end
|
360
382
|
|
361
383
|
def parse_config(path)
|
362
|
-
|
384
|
+
erb = ERB.new(File.read(path))
|
385
|
+
erb.filename = File.expand_path(path)
|
386
|
+
opts = load_yaml(erb.result) || {}
|
363
387
|
|
364
388
|
if opts.respond_to? :deep_symbolize_keys!
|
365
389
|
opts.deep_symbolize_keys!
|
@@ -375,6 +399,14 @@ module Sidekiq
|
|
375
399
|
opts
|
376
400
|
end
|
377
401
|
|
402
|
+
def load_yaml(src)
|
403
|
+
if Psych::VERSION > "4.0"
|
404
|
+
YAML.safe_load(src, permitted_classes: [Symbol], aliases: true)
|
405
|
+
else
|
406
|
+
YAML.load(src)
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
378
410
|
def parse_queues(opts, queues_and_weights)
|
379
411
|
queues_and_weights.each { |queue_and_weight| parse_queue(opts, *queue_and_weight) }
|
380
412
|
end
|
@@ -383,7 +415,7 @@ module Sidekiq
|
|
383
415
|
opts[:queues] ||= []
|
384
416
|
opts[:strict] = true if opts[:strict].nil?
|
385
417
|
raise ArgumentError, "queues: #{queue} cannot be defined twice" if opts[:queues].include?(queue)
|
386
|
-
[weight.to_i, 1].max.times { opts[:queues] << queue }
|
418
|
+
[weight.to_i, 1].max.times { opts[:queues] << queue.to_s }
|
387
419
|
opts[:strict] = false if weight.to_i > 0
|
388
420
|
end
|
389
421
|
|
@@ -394,3 +426,4 @@ module Sidekiq
|
|
394
426
|
end
|
395
427
|
|
396
428
|
require "sidekiq/systemd"
|
429
|
+
require "sidekiq/metrics/tracking" if ENV["SIDEKIQ_METRICS_BETA"]
|
data/lib/sidekiq/client.rb
CHANGED
@@ -2,9 +2,12 @@
|
|
2
2
|
|
3
3
|
require "securerandom"
|
4
4
|
require "sidekiq/middleware/chain"
|
5
|
+
require "sidekiq/job_util"
|
5
6
|
|
6
7
|
module Sidekiq
|
7
8
|
class Client
|
9
|
+
include Sidekiq::JobUtil
|
10
|
+
|
8
11
|
##
|
9
12
|
# Define client-side middleware:
|
10
13
|
#
|
@@ -12,14 +15,14 @@ module Sidekiq
|
|
12
15
|
# client.middleware do |chain|
|
13
16
|
# chain.use MyClientMiddleware
|
14
17
|
# end
|
15
|
-
# client.push('class' => '
|
18
|
+
# client.push('class' => 'SomeJob', 'args' => [1,2,3])
|
16
19
|
#
|
17
20
|
# All client instances default to the globally-defined
|
18
21
|
# Sidekiq.client_middleware but you can change as necessary.
|
19
22
|
#
|
20
23
|
def middleware(&block)
|
21
24
|
@chain ||= Sidekiq.client_middleware
|
22
|
-
if
|
25
|
+
if block
|
23
26
|
@chain = @chain.dup
|
24
27
|
yield @chain
|
25
28
|
end
|
@@ -46,16 +49,16 @@ module Sidekiq
|
|
46
49
|
# The main method used to push a job to Redis. Accepts a number of options:
|
47
50
|
#
|
48
51
|
# queue - the named queue to use, default 'default'
|
49
|
-
# class - the
|
52
|
+
# class - the job class to call, required
|
50
53
|
# args - an array of simple arguments to the perform method, must be JSON-serializable
|
51
54
|
# at - timestamp to schedule the job (optional), must be Numeric (e.g. Time.now.to_f)
|
52
55
|
# retry - whether to retry this job if it fails, default true or an integer number of retries
|
53
56
|
# backtrace - whether to save any error backtrace, default false
|
54
57
|
#
|
55
58
|
# If class is set to the class name, the jobs' options will be based on Sidekiq's default
|
56
|
-
#
|
59
|
+
# job options. Otherwise, they will be based on the job class's options.
|
57
60
|
#
|
58
|
-
# Any options valid for a
|
61
|
+
# Any options valid for a job class's sidekiq_options are also available here.
|
59
62
|
#
|
60
63
|
# All options must be strings, not symbols. NB: because we are serializing to JSON, all
|
61
64
|
# symbols in 'args' will be converted to strings. Note that +backtrace: true+ can take quite a bit of
|
@@ -64,13 +67,15 @@ module Sidekiq
|
|
64
67
|
# Returns a unique Job ID. If middleware stops the job, nil will be returned instead.
|
65
68
|
#
|
66
69
|
# Example:
|
67
|
-
# push('queue' => 'my_queue', 'class' =>
|
70
|
+
# push('queue' => 'my_queue', 'class' => MyJob, 'args' => ['foo', 1, :bat => 'bar'])
|
68
71
|
#
|
69
72
|
def push(item)
|
70
73
|
normed = normalize_item(item)
|
71
|
-
payload =
|
72
|
-
|
74
|
+
payload = middleware.invoke(item["class"], normed, normed["queue"], @redis_pool) do
|
75
|
+
normed
|
76
|
+
end
|
73
77
|
if payload
|
78
|
+
verify_json(payload)
|
74
79
|
raw_push([payload])
|
75
80
|
payload["jid"]
|
76
81
|
end
|
@@ -95,15 +100,20 @@ module Sidekiq
|
|
95
100
|
return [] if args.empty? # no jobs to push
|
96
101
|
|
97
102
|
at = items.delete("at")
|
98
|
-
raise ArgumentError, "Job 'at' must be a Numeric or an Array of Numeric timestamps" if at && (Array(at).empty? || !Array(at).all?(Numeric))
|
103
|
+
raise ArgumentError, "Job 'at' must be a Numeric or an Array of Numeric timestamps" if at && (Array(at).empty? || !Array(at).all? { |entry| entry.is_a?(Numeric) })
|
99
104
|
raise ArgumentError, "Job 'at' Array must have same size as 'args' Array" if at.is_a?(Array) && at.size != args.size
|
100
105
|
|
106
|
+
jid = items.delete("jid")
|
107
|
+
raise ArgumentError, "Explicitly passing 'jid' when pushing more than one job is not supported" if jid && args.size > 1
|
108
|
+
|
101
109
|
normed = normalize_item(items)
|
102
110
|
payloads = args.map.with_index { |job_args, index|
|
103
|
-
copy = normed.merge("args" => job_args, "jid" => SecureRandom.hex(12)
|
111
|
+
copy = normed.merge("args" => job_args, "jid" => SecureRandom.hex(12))
|
104
112
|
copy["at"] = (at.is_a?(Array) ? at[index] : at) if at
|
105
|
-
|
106
|
-
|
113
|
+
result = middleware.invoke(items["class"], copy, copy["queue"], @redis_pool) do
|
114
|
+
verify_json(copy)
|
115
|
+
copy
|
116
|
+
end
|
107
117
|
result || nil
|
108
118
|
}.compact
|
109
119
|
|
@@ -116,8 +126,8 @@ module Sidekiq
|
|
116
126
|
#
|
117
127
|
# pool = ConnectionPool.new { Redis.new }
|
118
128
|
# Sidekiq::Client.via(pool) do
|
119
|
-
#
|
120
|
-
#
|
129
|
+
# SomeJob.perform_async(1,2,3)
|
130
|
+
# SomeOtherJob.perform_async(1,2,3)
|
121
131
|
# end
|
122
132
|
#
|
123
133
|
# Generally this is only needed for very large Sidekiq installs processing
|
@@ -142,10 +152,10 @@ module Sidekiq
|
|
142
152
|
end
|
143
153
|
|
144
154
|
# Resque compatibility helpers. Note all helpers
|
145
|
-
# should go through
|
155
|
+
# should go through Sidekiq::Job#client_push.
|
146
156
|
#
|
147
157
|
# Example usage:
|
148
|
-
# Sidekiq::Client.enqueue(
|
158
|
+
# Sidekiq::Client.enqueue(MyJob, 'foo', 1, :bat => 'bar')
|
149
159
|
#
|
150
160
|
# Messages are enqueued to the 'default' queue.
|
151
161
|
#
|
@@ -154,14 +164,14 @@ module Sidekiq
|
|
154
164
|
end
|
155
165
|
|
156
166
|
# Example usage:
|
157
|
-
# Sidekiq::Client.enqueue_to(:queue_name,
|
167
|
+
# Sidekiq::Client.enqueue_to(:queue_name, MyJob, 'foo', 1, :bat => 'bar')
|
158
168
|
#
|
159
169
|
def enqueue_to(queue, klass, *args)
|
160
170
|
klass.client_push("queue" => queue, "class" => klass, "args" => args)
|
161
171
|
end
|
162
172
|
|
163
173
|
# Example usage:
|
164
|
-
# Sidekiq::Client.enqueue_to_in(:queue_name, 3.minutes,
|
174
|
+
# Sidekiq::Client.enqueue_to_in(:queue_name, 3.minutes, MyJob, 'foo', 1, :bat => 'bar')
|
165
175
|
#
|
166
176
|
def enqueue_to_in(queue, interval, klass, *args)
|
167
177
|
int = interval.to_f
|
@@ -175,7 +185,7 @@ module Sidekiq
|
|
175
185
|
end
|
176
186
|
|
177
187
|
# Example usage:
|
178
|
-
# Sidekiq::Client.enqueue_in(3.minutes,
|
188
|
+
# Sidekiq::Client.enqueue_in(3.minutes, MyJob, 'foo', 1, :bat => 'bar')
|
179
189
|
#
|
180
190
|
def enqueue_in(interval, klass, *args)
|
181
191
|
klass.perform_in(interval, *args)
|
@@ -186,8 +196,23 @@ module Sidekiq
|
|
186
196
|
|
187
197
|
def raw_push(payloads)
|
188
198
|
@redis_pool.with do |conn|
|
189
|
-
|
190
|
-
|
199
|
+
retryable = true
|
200
|
+
begin
|
201
|
+
conn.pipelined do |pipeline|
|
202
|
+
atomic_push(pipeline, payloads)
|
203
|
+
end
|
204
|
+
rescue RedisConnection.adapter::BaseError => ex
|
205
|
+
# 2550 Failover can cause the server to become a replica, need
|
206
|
+
# to disconnect and reopen the socket to get back to the primary.
|
207
|
+
# 4495 Use the same logic if we have a "Not enough replicas" error from the primary
|
208
|
+
# 4985 Use the same logic when a blocking command is force-unblocked
|
209
|
+
# The retry logic is copied from sidekiq.rb
|
210
|
+
if retryable && ex.message =~ /READONLY|NOREPLICAS|UNBLOCKED/
|
211
|
+
conn.disconnect!
|
212
|
+
retryable = false
|
213
|
+
retry
|
214
|
+
end
|
215
|
+
raise
|
191
216
|
end
|
192
217
|
end
|
193
218
|
true
|
@@ -195,7 +220,7 @@ module Sidekiq
|
|
195
220
|
|
196
221
|
def atomic_push(conn, payloads)
|
197
222
|
if payloads.first.key?("at")
|
198
|
-
conn.zadd("schedule", payloads.
|
223
|
+
conn.zadd("schedule", payloads.flat_map { |hash|
|
199
224
|
at = hash.delete("at").to_s
|
200
225
|
[at, Sidekiq.dump_json(hash)]
|
201
226
|
})
|
@@ -206,58 +231,9 @@ module Sidekiq
|
|
206
231
|
entry["enqueued_at"] = now
|
207
232
|
Sidekiq.dump_json(entry)
|
208
233
|
}
|
209
|
-
conn.sadd("queues", queue)
|
234
|
+
conn.sadd("queues", [queue])
|
210
235
|
conn.lpush("queue:#{queue}", to_push)
|
211
236
|
end
|
212
237
|
end
|
213
|
-
|
214
|
-
def process_single(worker_class, item)
|
215
|
-
queue = item["queue"]
|
216
|
-
|
217
|
-
middleware.invoke(worker_class, item, queue, @redis_pool) do
|
218
|
-
item
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
def validate(item)
|
223
|
-
raise(ArgumentError, "Job must be a Hash with 'class' and 'args' keys: `#{item}`") unless item.is_a?(Hash) && item.key?("class") && item.key?("args")
|
224
|
-
raise(ArgumentError, "Job args must be an Array: `#{item}`") unless item["args"].is_a?(Array)
|
225
|
-
raise(ArgumentError, "Job class must be either a Class or String representation of the class name: `#{item}`") unless item["class"].is_a?(Class) || item["class"].is_a?(String)
|
226
|
-
raise(ArgumentError, "Job 'at' must be a Numeric timestamp: `#{item}`") if item.key?("at") && !item["at"].is_a?(Numeric)
|
227
|
-
raise(ArgumentError, "Job tags must be an Array: `#{item}`") if item["tags"] && !item["tags"].is_a?(Array)
|
228
|
-
end
|
229
|
-
|
230
|
-
def normalize_item(item)
|
231
|
-
# 6.0.0 push_bulk bug, #4321
|
232
|
-
# TODO Remove after a while...
|
233
|
-
item.delete("at") if item.key?("at") && item["at"].nil?
|
234
|
-
|
235
|
-
validate(item)
|
236
|
-
# raise(ArgumentError, "Arguments must be native JSON types, see https://github.com/mperham/sidekiq/wiki/Best-Practices") unless JSON.load(JSON.dump(item['args'])) == item['args']
|
237
|
-
|
238
|
-
# merge in the default sidekiq_options for the item's class and/or wrapped element
|
239
|
-
# this allows ActiveJobs to control sidekiq_options too.
|
240
|
-
defaults = normalized_hash(item["class"])
|
241
|
-
defaults = defaults.merge(item["wrapped"].get_sidekiq_options) if item["wrapped"].respond_to?("get_sidekiq_options")
|
242
|
-
item = defaults.merge(item)
|
243
|
-
|
244
|
-
raise(ArgumentError, "Job must include a valid queue name") if item["queue"].nil? || item["queue"] == ""
|
245
|
-
|
246
|
-
item["class"] = item["class"].to_s
|
247
|
-
item["queue"] = item["queue"].to_s
|
248
|
-
item["jid"] ||= SecureRandom.hex(12)
|
249
|
-
item["created_at"] ||= Time.now.to_f
|
250
|
-
|
251
|
-
item
|
252
|
-
end
|
253
|
-
|
254
|
-
def normalized_hash(item_class)
|
255
|
-
if item_class.is_a?(Class)
|
256
|
-
raise(ArgumentError, "Message must include a Sidekiq::Worker class, not class name: #{item_class.ancestors.inspect}") unless item_class.respond_to?("get_sidekiq_options")
|
257
|
-
item_class.get_sidekiq_options
|
258
|
-
else
|
259
|
-
Sidekiq.default_worker_options
|
260
|
-
end
|
261
|
-
end
|
262
238
|
end
|
263
239
|
end
|
@@ -1,15 +1,8 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "socket"
|
4
|
-
require "securerandom"
|
5
|
-
require "sidekiq/exception_handler"
|
6
|
-
|
7
1
|
module Sidekiq
|
8
2
|
##
|
9
|
-
#
|
10
|
-
#
|
11
|
-
|
12
|
-
include ExceptionHandler
|
3
|
+
# Sidekiq::Component assumes a config instance is available at @config
|
4
|
+
module Component # :nodoc:
|
5
|
+
attr_reader :config
|
13
6
|
|
14
7
|
def watchdog(last_words)
|
15
8
|
yield
|
@@ -26,11 +19,11 @@ module Sidekiq
|
|
26
19
|
end
|
27
20
|
|
28
21
|
def logger
|
29
|
-
|
22
|
+
config.logger
|
30
23
|
end
|
31
24
|
|
32
25
|
def redis(&block)
|
33
|
-
|
26
|
+
config.redis(&block)
|
34
27
|
end
|
35
28
|
|
36
29
|
def tid
|
@@ -49,11 +42,16 @@ module Sidekiq
|
|
49
42
|
@@identity ||= "#{hostname}:#{::Process.pid}:#{process_nonce}"
|
50
43
|
end
|
51
44
|
|
45
|
+
def handle_exception(ex, ctx = {})
|
46
|
+
config.handle_exception(ex, ctx)
|
47
|
+
end
|
48
|
+
|
52
49
|
def fire_event(event, options = {})
|
50
|
+
oneshot = options.fetch(:oneshot, true)
|
53
51
|
reverse = options[:reverse]
|
54
52
|
reraise = options[:reraise]
|
55
53
|
|
56
|
-
arr =
|
54
|
+
arr = config[:lifecycle_events][event]
|
57
55
|
arr.reverse! if reverse
|
58
56
|
arr.each do |block|
|
59
57
|
block.call
|
@@ -61,7 +59,7 @@ module Sidekiq
|
|
61
59
|
handle_exception(ex, {context: "Exception during Sidekiq lifecycle event.", event: event})
|
62
60
|
raise ex if reraise
|
63
61
|
end
|
64
|
-
arr.clear
|
62
|
+
arr.clear if oneshot # once we've fired an event, we never fire it again
|
65
63
|
end
|
66
64
|
end
|
67
65
|
end
|
data/lib/sidekiq/delay.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Sidekiq
|
3
|
+
module Sidekiq # :nodoc:
|
4
4
|
module Extensions
|
5
5
|
def self.enable_delay!
|
6
|
+
warn "Sidekiq's Delayed Extensions will be removed in Sidekiq 7.0", uplevel: 1
|
7
|
+
|
6
8
|
if defined?(::ActiveSupport)
|
7
9
|
require "sidekiq/extensions/active_record"
|
8
10
|
require "sidekiq/extensions/action_mailer"
|
@@ -10,7 +10,7 @@ module Sidekiq
|
|
10
10
|
def initialize(performable, target, options = {})
|
11
11
|
@performable = performable
|
12
12
|
@target = target
|
13
|
-
@opts = options
|
13
|
+
@opts = options.transform_keys(&:to_s)
|
14
14
|
end
|
15
15
|
|
16
16
|
def method_missing(name, *args)
|
@@ -24,7 +24,9 @@ module Sidekiq
|
|
24
24
|
if marshalled.size > SIZE_LIMIT
|
25
25
|
::Sidekiq.logger.warn { "#{@target}.#{name} job argument is #{marshalled.bytesize} bytes, you should refactor it to reduce the size" }
|
26
26
|
end
|
27
|
-
@performable.client_push({"class" => @performable,
|
27
|
+
@performable.client_push({"class" => @performable,
|
28
|
+
"args" => [marshalled],
|
29
|
+
"display_class" => "#{@target}.#{name}"}.merge(@opts))
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|