sidekiq 6.4.1 → 6.5.0

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.

Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +43 -1
  3. data/README.md +1 -1
  4. data/bin/sidekiqload +16 -10
  5. data/lib/sidekiq/api.rb +42 -33
  6. data/lib/sidekiq/cli.rb +37 -36
  7. data/lib/sidekiq/client.rb +25 -26
  8. data/lib/sidekiq/component.rb +64 -0
  9. data/lib/sidekiq/extensions/generic_proxy.rb +1 -1
  10. data/lib/sidekiq/fetch.rb +15 -13
  11. data/lib/sidekiq/job_retry.rb +27 -26
  12. data/lib/sidekiq/job_util.rb +15 -9
  13. data/lib/sidekiq/launcher.rb +31 -29
  14. data/lib/sidekiq/logger.rb +5 -19
  15. data/lib/sidekiq/manager.rb +28 -25
  16. data/lib/sidekiq/middleware/chain.rb +22 -13
  17. data/lib/sidekiq/middleware/current_attributes.rb +4 -0
  18. data/lib/sidekiq/middleware/i18n.rb +6 -4
  19. data/lib/sidekiq/middleware/modules.rb +19 -0
  20. data/lib/sidekiq/monitor.rb +1 -1
  21. data/lib/sidekiq/paginator.rb +2 -2
  22. data/lib/sidekiq/processor.rb +38 -38
  23. data/lib/sidekiq/rails.rb +15 -8
  24. data/lib/sidekiq/redis_client_adapter.rb +154 -0
  25. data/lib/sidekiq/redis_connection.rb +81 -48
  26. data/lib/sidekiq/ring_buffer.rb +29 -0
  27. data/lib/sidekiq/scheduled.rb +11 -10
  28. data/lib/sidekiq/testing/inline.rb +4 -4
  29. data/lib/sidekiq/testing.rb +37 -36
  30. data/lib/sidekiq/transaction_aware_client.rb +45 -0
  31. data/lib/sidekiq/version.rb +1 -1
  32. data/lib/sidekiq/web/csrf_protection.rb +2 -2
  33. data/lib/sidekiq/web/helpers.rb +4 -4
  34. data/lib/sidekiq/worker.rb +18 -13
  35. data/lib/sidekiq.rb +97 -30
  36. data/web/assets/javascripts/application.js +58 -26
  37. data/web/assets/stylesheets/application.css +1 -2
  38. data/web/locales/pt-br.yml +27 -9
  39. data/web/views/_summary.erb +1 -1
  40. data/web/views/busy.erb +3 -3
  41. metadata +7 -4
  42. data/lib/sidekiq/exception_handler.rb +0 -27
  43. data/lib/sidekiq/util.rb +0 -108
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99c9e264c092b88ea726be158fafe5bbab91f82f4b5864dee406280622e98e4b
4
- data.tar.gz: acd72bd99929d7c9d129cb9662276cc5adb7214de07cd4fc8accf6b9d521994a
3
+ metadata.gz: dedc78179d612e64435e57f0f6644c2645c06ffdc24151c9ad51df4035b51efa
4
+ data.tar.gz: 5987eba09190793cfccbff56066b54b5308a1fe74be7551cb5b9d6d03d256c3a
5
5
  SHA512:
6
- metadata.gz: 622c25276c017302c1a9d144e9366043ba359b2c3b0c57d4e7baad8f9de2e9c9969a86c91acdbefcf736af92e297c4e1fbe2008aa41e0c1accadda77dd0724f5
7
- data.tar.gz: 7e64012a5368cb0158ecaa50cdea6447709a64dd3a2816b36a31e7f17d70fffff81bd8d317c0cc1f9a6317adcffad9c200c48f9ca4bf208afba819ff7a07738e
6
+ metadata.gz: 9a26b5eb6e2248870f07ede054cac8330b52ad548d27b40d3950b6d985ef5ef8359e4dfc062757dc4b479036f0b2716bacfc821a20bd63413ea7c3f772bc6ead
7
+ data.tar.gz: 46a35f7f27693364b1b6077e602d3f69e476508654157f48fcd457a70bbcdb563f8515812ef37abae207604596e1d42f78132ac54471109f913e87c11a707cdb
data/Changes.md CHANGED
@@ -2,7 +2,42 @@
2
2
 
3
3
  [Sidekiq Changes](https://github.com/mperham/sidekiq/blob/main/Changes.md) | [Sidekiq Pro Changes](https://github.com/mperham/sidekiq/blob/main/Pro-Changes.md) | [Sidekiq Enterprise Changes](https://github.com/mperham/sidekiq/blob/main/Ent-Changes.md)
4
4
 
5
- HEAD
5
+ 6.5.0
6
+ ---------
7
+
8
+ - Substantial refactoring of Sidekiq server internals, part of a larger effort
9
+ to reduce Sidekiq's internal usage of global methods and data, see [docs/component.md](docs/component.md),
10
+ [docs/global_to_local.md](docs/global_to_local.md) and [docs/middleware.md](docs/middleware.md).
11
+ - **Add beta support for the `redis-client` gem**. This will become the default Redis driver in Sidekiq 7.0. [#5298]
12
+ Read more: https://github.com/mperham/sidekiq/wiki/Using-redis-client
13
+ - **Add beta support for DB transaction-aware client** [#5291]
14
+ Add this line to your initializer and any jobs created during a transaction
15
+ will only be pushed to Redis **after the transaction commits**. You will need to add the
16
+ `after_commit_everywhere` gem to your Gemfile.
17
+ ```ruby
18
+ Sidekiq.transactional_push!
19
+ ```
20
+ This feature does not have a lot of production usage yet; please try it out and let us
21
+ know if you have any issues. It will be fully supported in Sidekiq 7.0 or removed if it
22
+ proves problematic.
23
+ - Fix regression with middleware arguments [#5312]
24
+
25
+ 6.4.2
26
+ ---------
27
+
28
+ - Strict argument checking now runs after client-side middleware [#5246]
29
+ - Fix page events with live polling [#5184]
30
+ - Many under-the-hood changes to remove all usage of the term "worker"
31
+ from the Sidekiq codebase and APIs. This mostly involved RDoc and local
32
+ variable names but a few constants and public APIs were changed. The old
33
+ APIs will be removed in Sidekiq 7.0.
34
+ ```
35
+ Sidekiq::DEFAULT_WORKER_OPTIONS -> Sidekiq.default_job_options
36
+ Sidekiq.default_worker_options -> Sidekiq.default_job_options
37
+ Sidekiq::Queues["default"].jobs_by_worker(HardJob) -> Sidekiq::Queues["default"].jobs_by_class(HardJob)
38
+ ```
39
+
40
+ 6.4.1
6
41
  ---------
7
42
 
8
43
  - Fix pipeline/multi deprecations in redis-rb 4.6
@@ -319,6 +354,13 @@ See the [Logging wiki page](https://github.com/mperham/sidekiq/wiki/Logging) for
319
354
  - Integrate the StandardRB code formatter to ensure consistent code
320
355
  styling. [#4114, gearnode]
321
356
 
357
+ 5.2.10
358
+ ---------
359
+
360
+ - Backport fix for CVE-2022-23837.
361
+ - Migrate to `exists?` for redis-rb.
362
+ - Lock redis-rb to <4.6 to avoid deprecations.
363
+
322
364
  5.2.9
323
365
  ---------
324
366
 
data/README.md CHANGED
@@ -36,7 +36,7 @@ Sidekiq 6.0 supports Rails 5.0+ but does not require it.
36
36
  Installation
37
37
  -----------------
38
38
 
39
- gem install sidekiq
39
+ bundle add sidekiq
40
40
 
41
41
 
42
42
  Getting Started
data/bin/sidekiqload CHANGED
@@ -11,6 +11,10 @@ Bundler.require(:default, :load_test)
11
11
  require_relative "../lib/sidekiq/cli"
12
12
  require_relative "../lib/sidekiq/launcher"
13
13
 
14
+ if ENV["SIDEKIQ_REDIS_CLIENT"]
15
+ Sidekiq::RedisConnection.adapter = :redis_client
16
+ end
17
+
14
18
  Sidekiq.configure_server do |config|
15
19
  config.options[:concurrency] = 10
16
20
  config.redis = {db: 13, port: 6380}
@@ -36,7 +40,6 @@ end
36
40
 
37
41
  # brew tap shopify/shopify
38
42
  # brew install toxiproxy
39
- # gem install toxiproxy
40
43
  # run `toxiproxy-server` in a separate terminal window.
41
44
  require "toxiproxy"
42
45
  # simulate a non-localhost network for realer-world conditions.
@@ -90,12 +93,7 @@ iter = 50
90
93
  count = 10_000
91
94
 
92
95
  iter.times do
93
- arr = Array.new(count) do
94
- []
95
- end
96
- count.times do |idx|
97
- arr[idx][0] = idx
98
- end
96
+ arr = Array.new(count) { |idx| [idx] }
99
97
  Sidekiq::Client.push_bulk("class" => LoadWorker, "args" => arr)
100
98
  end
101
99
  Sidekiq.logger.error "Created #{count * iter} jobs"
@@ -124,15 +122,23 @@ Monitoring = Thread.new do
124
122
  end
125
123
  end
126
124
 
125
+ def with_latency(latency, &block)
126
+ Sidekiq.logger.error "Simulating #{latency}ms of latency between Sidekiq and redis"
127
+ if latency > 0
128
+ Toxiproxy[:redis].downstream(:latency, latency: latency).apply(&block)
129
+ else
130
+ yield
131
+ end
132
+ end
133
+
127
134
  begin
128
135
  # RubyProf::exclude_threads = [ Monitoring ]
129
136
  # RubyProf.start
130
137
  events = Sidekiq.options[:lifecycle_events][:startup]
131
138
  events.each(&:call)
132
139
  events.clear
133
-
134
- Sidekiq.logger.error "Simulating 1ms of latency between Sidekiq and redis"
135
- Toxiproxy[:redis].downstream(:latency, latency: 1).apply do
140
+
141
+ with_latency(Integer(ENV.fetch("LATENCY", "1"))) do
136
142
  launcher = Sidekiq::Launcher.new(Sidekiq.options)
137
143
  launcher.run
138
144
 
data/lib/sidekiq/api.rb CHANGED
@@ -191,7 +191,7 @@ module Sidekiq
191
191
  stat_hash[dates[idx]] = value ? value.to_i : 0
192
192
  end
193
193
  end
194
- rescue Redis::CommandError
194
+ rescue RedisConnection.adapter::CommandError
195
195
  # mget will trigger a CROSSSLOT error when run against a Cluster
196
196
  # TODO Someone want to add Cluster support?
197
197
  end
@@ -294,6 +294,10 @@ module Sidekiq
294
294
  end
295
295
  end
296
296
  alias_method :💣, :clear
297
+
298
+ def as_json(options = nil) # :nodoc:
299
+ {name: name} # 5336
300
+ end
297
301
  end
298
302
 
299
303
  ##
@@ -354,31 +358,31 @@ module Sidekiq
354
358
  def display_args
355
359
  # Unwrap known wrappers so they show up in a human-friendly manner in the Web UI
356
360
  @display_args ||= case klass
357
- when /\ASidekiq::Extensions::Delayed/
358
- safe_load(args[0], args) do |_, _, arg, kwarg|
359
- if !kwarg || kwarg.empty?
360
- arg
361
- else
362
- [arg, kwarg]
363
- end
364
- end
365
- when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
366
- job_args = self["wrapped"] ? args[0]["arguments"] : []
367
- if (self["wrapped"] || args[0]) == "ActionMailer::DeliveryJob"
368
- # remove MailerClass, mailer_method and 'deliver_now'
369
- job_args.drop(3)
370
- elsif (self["wrapped"] || args[0]) == "ActionMailer::MailDeliveryJob"
371
- # remove MailerClass, mailer_method and 'deliver_now'
372
- job_args.drop(3).first["args"]
373
- else
374
- job_args
375
- end
376
- else
377
- if self["encrypt"]
378
- # no point in showing 150+ bytes of random garbage
379
- args[-1] = "[encrypted data]"
380
- end
381
- args
361
+ when /\ASidekiq::Extensions::Delayed/
362
+ safe_load(args[0], args) do |_, _, arg, kwarg|
363
+ if !kwarg || kwarg.empty?
364
+ arg
365
+ else
366
+ [arg, kwarg]
367
+ end
368
+ end
369
+ when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
370
+ job_args = self["wrapped"] ? args[0]["arguments"] : []
371
+ if (self["wrapped"] || args[0]) == "ActionMailer::DeliveryJob"
372
+ # remove MailerClass, mailer_method and 'deliver_now'
373
+ job_args.drop(3)
374
+ elsif (self["wrapped"] || args[0]) == "ActionMailer::MailDeliveryJob"
375
+ # remove MailerClass, mailer_method and 'deliver_now'
376
+ job_args.drop(3).first["args"]
377
+ else
378
+ job_args
379
+ end
380
+ else
381
+ if self["encrypt"]
382
+ # no point in showing 150+ bytes of random garbage
383
+ args[-1] = "[encrypted data]"
384
+ end
385
+ args
382
386
  end
383
387
  end
384
388
 
@@ -442,7 +446,8 @@ module Sidekiq
442
446
  rescue => ex
443
447
  # #1761 in dev mode, it's possible to have jobs enqueued which haven't been loaded into
444
448
  # memory yet so the YAML can't be loaded.
445
- Sidekiq.logger.warn "Unable to load YAML: #{ex.message}" unless Sidekiq.options[:environment] == "development"
449
+ # TODO is this still necessary? Zeitwerk reloader should handle?
450
+ Sidekiq.logger.warn "Unable to load YAML: #{ex.message}" unless Sidekiq.config[:environment] == "development"
446
451
  default
447
452
  end
448
453
 
@@ -470,7 +475,7 @@ module Sidekiq
470
475
 
471
476
  def initialize(parent, score, item)
472
477
  super(item)
473
- @score = score
478
+ @score = Float(score)
474
479
  @parent = parent
475
480
  end
476
481
 
@@ -587,6 +592,10 @@ module Sidekiq
587
592
  end
588
593
  end
589
594
  alias_method :💣, :clear
595
+
596
+ def as_json(options = nil) # :nodoc:
597
+ {name: name} # 5336
598
+ end
590
599
  end
591
600
 
592
601
  class JobSet < SortedSet
@@ -606,7 +615,7 @@ module Sidekiq
606
615
  range_start = page * page_size + offset_size
607
616
  range_end = range_start + page_size - 1
608
617
  elements = Sidekiq.redis { |conn|
609
- conn.zrange name, range_start, range_end, with_scores: true
618
+ conn.zrange name, range_start, range_end, withscores: true
610
619
  }
611
620
  break if elements.empty?
612
621
  page -= 1
@@ -629,7 +638,7 @@ module Sidekiq
629
638
  end
630
639
 
631
640
  elements = Sidekiq.redis { |conn|
632
- conn.zrangebyscore(name, begin_score, end_score, with_scores: true)
641
+ conn.zrangebyscore(name, begin_score, end_score, withscores: true)
633
642
  }
634
643
 
635
644
  elements.each_with_object([]) do |element, result|
@@ -758,11 +767,11 @@ module Sidekiq
758
767
  end
759
768
 
760
769
  def self.max_jobs
761
- Sidekiq.options[:dead_max_jobs]
770
+ Sidekiq[:dead_max_jobs]
762
771
  end
763
772
 
764
773
  def self.timeout
765
- Sidekiq.options[:dead_timeout_in_seconds]
774
+ Sidekiq[:dead_timeout_in_seconds]
766
775
  end
767
776
  end
768
777
 
@@ -964,7 +973,7 @@ module Sidekiq
964
973
  procs.sort.each do |key|
965
974
  valid, workers = conn.pipelined { |pipeline|
966
975
  pipeline.exists?(key)
967
- pipeline.hgetall("#{key}:workers")
976
+ pipeline.hgetall("#{key}:work")
968
977
  }
969
978
  next unless valid
970
979
  workers.each_pair do |tid, json|
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
15
  module Sidekiq
16
16
  class CLI
17
- include Util
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? && Sidekiq.log_formatter.is_a?(Sidekiq::Logger::Formatters::Pretty)
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 = Sidekiq.redis_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 = Sidekiq.redis_pool.size
89
- needed = Sidekiq.options[:concurrency] + 2
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
- Sidekiq.options[:identity] = identity
98
+ @config[:identity] = identity
94
99
 
95
100
  # Touch middleware so it isn't lazy loaded by multiple threads, #3043
96
- Sidekiq.server_middleware
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: #{Sidekiq.client_middleware.map(&:klass).join(", ")}" }
103
- logger.debug { "Server Middleware: #{Sidekiq.server_middleware.map(&:klass).join(", ")}" }
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,13 +115,13 @@ module Sidekiq
110
115
  logger.info "Starting processing, hit Ctrl-C to stop"
111
116
  end
112
117
 
113
- @launcher = Sidekiq::Launcher.new(options)
118
+ @launcher = Sidekiq::Launcher.new(@config)
114
119
 
115
120
  begin
116
121
  launcher.run
117
122
 
118
- while (readable_io = self_read.wait_readable)
119
- signal = readable_io.gets.strip
123
+ while self_read.wait_readable
124
+ signal = self_read.gets.strip
120
125
  handle_signal(signal)
121
126
  end
122
127
  rescue Interrupt
@@ -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
- Sidekiq.logger.info "Received TSTP, no longer accepting new work"
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
- Sidekiq.logger.warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread.name}"
186
+ cli.logger.warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread.name}"
182
187
  if thread.backtrace
183
- Sidekiq.logger.warn thread.backtrace.join("\n")
188
+ cli.logger.warn thread.backtrace.join("\n")
184
189
  else
185
- Sidekiq.logger.warn "<no backtrace available>"
190
+ cli.logger.warn "<no backtrace available>"
186
191
  end
187
192
  end
188
193
  }
189
194
  }
190
- UNHANDLED_SIGNAL_HANDLER = ->(cli) { Sidekiq.logger.info "No signal handler registered, ignoring" }
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
- Sidekiq.logger.debug "Got #{sig} signal"
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(options[:require], "config")
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
- options.merge!(opts)
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?(options[:require])
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("#{options[:require]}/config/environment.rb")
274
+ require File.expand_path("#{@config[:require]}/config/environment.rb")
274
275
  end
275
- options[:tag] ||= default_tag
276
+ @config[:tag] ||= default_tag
276
277
  else
277
- require options[:require]
278
+ require @config[:require]
278
279
  end
279
280
  end
280
281
 
@@ -291,18 +292,18 @@ module Sidekiq
291
292
  end
292
293
 
293
294
  def validate!
294
- if !File.exist?(options[:require]) ||
295
- (File.directory?(options[:require]) && !File.exist?("#{options[:require]}/config/application.rb"))
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
- logger.info " to load your worker classes with -r [DIR|FILE]."
299
+ logger.info " to load your job classes with -r [DIR|FILE]."
299
300
  logger.info "=================================================================="
300
301
  logger.info @parser
301
302
  die(1)
302
303
  end
303
304
 
304
305
  [:concurrency, :timeout].each do |opt|
305
- raise ArgumentError, "#{opt}: #{options[opt]} is not a valid value" if options.key?(opt) && options[opt].to_i <= 0
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
 
@@ -336,7 +337,7 @@ module Sidekiq
336
337
  parse_queue opts, queue, weight
337
338
  end
338
339
 
339
- o.on "-r", "--require [PATH|DIR]", "Location of Rails application with workers or file to require" do |arg|
340
+ o.on "-r", "--require [PATH|DIR]", "Location of Rails application with jobs or file to require" do |arg|
340
341
  opts[:require] = arg
341
342
  end
342
343
 
@@ -376,7 +377,7 @@ module Sidekiq
376
377
  end
377
378
 
378
379
  def initialize_logger
379
- Sidekiq.logger.level = ::Logger::DEBUG if options[:verbose]
380
+ @config.logger.level = ::Logger::DEBUG if @config[:verbose]
380
381
  end
381
382
 
382
383
  def parse_config(path)
@@ -15,7 +15,7 @@ module Sidekiq
15
15
  # client.middleware do |chain|
16
16
  # chain.use MyClientMiddleware
17
17
  # end
18
- # client.push('class' => 'SomeWorker', 'args' => [1,2,3])
18
+ # client.push('class' => 'SomeJob', 'args' => [1,2,3])
19
19
  #
20
20
  # All client instances default to the globally-defined
21
21
  # Sidekiq.client_middleware but you can change as necessary.
@@ -49,16 +49,16 @@ module Sidekiq
49
49
  # The main method used to push a job to Redis. Accepts a number of options:
50
50
  #
51
51
  # queue - the named queue to use, default 'default'
52
- # class - the worker class to call, required
52
+ # class - the job class to call, required
53
53
  # args - an array of simple arguments to the perform method, must be JSON-serializable
54
54
  # at - timestamp to schedule the job (optional), must be Numeric (e.g. Time.now.to_f)
55
55
  # retry - whether to retry this job if it fails, default true or an integer number of retries
56
56
  # backtrace - whether to save any error backtrace, default false
57
57
  #
58
58
  # If class is set to the class name, the jobs' options will be based on Sidekiq's default
59
- # worker options. Otherwise, they will be based on the job class's options.
59
+ # job options. Otherwise, they will be based on the job class's options.
60
60
  #
61
- # Any options valid for a worker class's sidekiq_options are also available here.
61
+ # Any options valid for a job class's sidekiq_options are also available here.
62
62
  #
63
63
  # All options must be strings, not symbols. NB: because we are serializing to JSON, all
64
64
  # symbols in 'args' will be converted to strings. Note that +backtrace: true+ can take quite a bit of
@@ -67,13 +67,15 @@ module Sidekiq
67
67
  # Returns a unique Job ID. If middleware stops the job, nil will be returned instead.
68
68
  #
69
69
  # Example:
70
- # push('queue' => 'my_queue', 'class' => MyWorker, 'args' => ['foo', 1, :bat => 'bar'])
70
+ # push('queue' => 'my_queue', 'class' => MyJob, 'args' => ['foo', 1, :bat => 'bar'])
71
71
  #
72
72
  def push(item)
73
73
  normed = normalize_item(item)
74
- payload = process_single(item["class"], normed)
75
-
74
+ payload = middleware.invoke(item["class"], normed, normed["queue"], @redis_pool) do
75
+ normed
76
+ end
76
77
  if payload
78
+ verify_json(payload)
77
79
  raw_push([payload])
78
80
  payload["jid"]
79
81
  end
@@ -101,12 +103,17 @@ module Sidekiq
101
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) })
102
104
  raise ArgumentError, "Job 'at' Array must have same size as 'args' Array" if at.is_a?(Array) && at.size != args.size
103
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
+
104
109
  normed = normalize_item(items)
105
110
  payloads = args.map.with_index { |job_args, index|
106
111
  copy = normed.merge("args" => job_args, "jid" => SecureRandom.hex(12))
107
112
  copy["at"] = (at.is_a?(Array) ? at[index] : at) if at
108
-
109
- result = process_single(items["class"], copy)
113
+ result = middleware.invoke(items["class"], copy, copy["queue"], @redis_pool) do
114
+ verify_json(copy)
115
+ copy
116
+ end
110
117
  result || nil
111
118
  }.compact
112
119
 
@@ -119,8 +126,8 @@ module Sidekiq
119
126
  #
120
127
  # pool = ConnectionPool.new { Redis.new }
121
128
  # Sidekiq::Client.via(pool) do
122
- # SomeWorker.perform_async(1,2,3)
123
- # SomeOtherWorker.perform_async(1,2,3)
129
+ # SomeJob.perform_async(1,2,3)
130
+ # SomeOtherJob.perform_async(1,2,3)
124
131
  # end
125
132
  #
126
133
  # Generally this is only needed for very large Sidekiq installs processing
@@ -145,10 +152,10 @@ module Sidekiq
145
152
  end
146
153
 
147
154
  # Resque compatibility helpers. Note all helpers
148
- # should go through Worker#client_push.
155
+ # should go through Sidekiq::Job#client_push.
149
156
  #
150
157
  # Example usage:
151
- # Sidekiq::Client.enqueue(MyWorker, 'foo', 1, :bat => 'bar')
158
+ # Sidekiq::Client.enqueue(MyJob, 'foo', 1, :bat => 'bar')
152
159
  #
153
160
  # Messages are enqueued to the 'default' queue.
154
161
  #
@@ -157,14 +164,14 @@ module Sidekiq
157
164
  end
158
165
 
159
166
  # Example usage:
160
- # Sidekiq::Client.enqueue_to(:queue_name, MyWorker, 'foo', 1, :bat => 'bar')
167
+ # Sidekiq::Client.enqueue_to(:queue_name, MyJob, 'foo', 1, :bat => 'bar')
161
168
  #
162
169
  def enqueue_to(queue, klass, *args)
163
170
  klass.client_push("queue" => queue, "class" => klass, "args" => args)
164
171
  end
165
172
 
166
173
  # Example usage:
167
- # Sidekiq::Client.enqueue_to_in(:queue_name, 3.minutes, MyWorker, 'foo', 1, :bat => 'bar')
174
+ # Sidekiq::Client.enqueue_to_in(:queue_name, 3.minutes, MyJob, 'foo', 1, :bat => 'bar')
168
175
  #
169
176
  def enqueue_to_in(queue, interval, klass, *args)
170
177
  int = interval.to_f
@@ -178,7 +185,7 @@ module Sidekiq
178
185
  end
179
186
 
180
187
  # Example usage:
181
- # Sidekiq::Client.enqueue_in(3.minutes, MyWorker, 'foo', 1, :bat => 'bar')
188
+ # Sidekiq::Client.enqueue_in(3.minutes, MyJob, 'foo', 1, :bat => 'bar')
182
189
  #
183
190
  def enqueue_in(interval, klass, *args)
184
191
  klass.perform_in(interval, *args)
@@ -194,7 +201,7 @@ module Sidekiq
194
201
  conn.pipelined do |pipeline|
195
202
  atomic_push(pipeline, payloads)
196
203
  end
197
- rescue Redis::BaseError => ex
204
+ rescue RedisConnection.adapter::BaseError => ex
198
205
  # 2550 Failover can cause the server to become a replica, need
199
206
  # to disconnect and reopen the socket to get back to the primary.
200
207
  # 4495 Use the same logic if we have a "Not enough replicas" error from the primary
@@ -213,7 +220,7 @@ module Sidekiq
213
220
 
214
221
  def atomic_push(conn, payloads)
215
222
  if payloads.first.key?("at")
216
- conn.zadd("schedule", payloads.map { |hash|
223
+ conn.zadd("schedule", *payloads.map { |hash|
217
224
  at = hash.delete("at").to_s
218
225
  [at, Sidekiq.dump_json(hash)]
219
226
  })
@@ -228,13 +235,5 @@ module Sidekiq
228
235
  conn.lpush("queue:#{queue}", to_push)
229
236
  end
230
237
  end
231
-
232
- def process_single(worker_class, item)
233
- queue = item["queue"]
234
-
235
- middleware.invoke(worker_class, item, queue, @redis_pool) do
236
- item
237
- end
238
- end
239
238
  end
240
239
  end