sidekiq 7.0.0.beta1 → 7.0.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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31722cec9da8b32488242bbcf40b46f3e2eaf8f9e5f5acefb4be306e6a3521e1
4
- data.tar.gz: 625639dd35227dd5c9e36d04e93afbb3f8ae6372c532625453a0d681fac19a65
3
+ metadata.gz: 9c6762c97172b3f8e4b7cc1fd940756ee8796faf70ece8d5e9ede9e2dc7797fe
4
+ data.tar.gz: 905e0e1f381e1c40832ab2137589161fcccfb63c847ad36c9cca15765d952659
5
5
  SHA512:
6
- metadata.gz: 9471e077c2122b7b8fe94d075d1203d83d463608485852237ede31f9307b57233bb6cb0ba867f8556c080d61b01a5eb5efb7f1e3d68835e5bd16adc2630c65e1
7
- data.tar.gz: 95b6c47592ba8641b4398859dca9c80b0d644c9e61cffec5482ff5741047daa9523f9cc5efb1974e197f3f06cab07321a5aca8b1838635372b3ea26e37cfca45
6
+ metadata.gz: acfc9bb74585cc65ad1af27e263668ec154ac791baa99de2a1542cfe462a7b13544a758a7bd574d623088c9e683f705437cc4e4495f05e57770037d030214a44
7
+ data.tar.gz: 31320e6cd2fab0d253f3a32616f51360c4ad6a9ef30acef5f88a6ccc6eaf75e04b76ea12dd053dd29442d96fa49234f65e14801e7600cf0f300c023d75aecf43
data/Changes.md CHANGED
@@ -2,9 +2,19 @@
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
+ main
6
6
  ----------
7
7
 
8
+ - Embedded mode!
9
+ - Capsules!!
10
+ - Job Execution metrics!!!
11
+ - See `docs/7.0-Upgrade.md` for release notes
12
+
13
+ 6-x
14
+ ----------
15
+
16
+ - Add pagination to Busy page [#5556]
17
+ - Speed up WorkSet#each [#5559]
8
18
  - Adjust CurrentAttributes to work with the String class name so we aren't referencing
9
19
  the Class within a Rails initializer [#5536]
10
20
 
data/bin/sidekiqload CHANGED
@@ -19,7 +19,7 @@ x = Sidekiq.configure_embed do |config|
19
19
  end
20
20
 
21
21
  class LoadWorker
22
- include Sidekiq::Worker
22
+ include Sidekiq::Job
23
23
  sidekiq_options retry: 1
24
24
  sidekiq_retry_in do |x|
25
25
  1
data/lib/sidekiq/api.rb CHANGED
@@ -1034,24 +1034,24 @@ module Sidekiq
1034
1034
 
1035
1035
  def each(&block)
1036
1036
  results = []
1037
+ procs = nil
1038
+ all_works = nil
1039
+
1037
1040
  Sidekiq.redis do |conn|
1038
- procs = conn.sscan("processes").to_a
1039
- procs.sort.each do |key|
1040
- valid, workers = conn.pipelined { |pipeline|
1041
- pipeline.exists(key)
1041
+ procs = conn.sscan("processes").to_a.sort
1042
+ all_works = conn.pipelined do |pipeline|
1043
+ procs.each do |key|
1042
1044
  pipeline.hgetall("#{key}:work")
1043
- }
1044
- next unless valid > 0
1045
- workers.each_pair do |tid, json|
1046
- hsh = Sidekiq.load_json(json)
1047
- p = hsh["payload"]
1048
- # avoid breaking API, this is a side effect of the JSON optimization in #4316
1049
- hsh["payload"] = Sidekiq.load_json(p) if p.is_a?(String)
1050
- results << [key, tid, hsh]
1051
1045
  end
1052
1046
  end
1053
1047
  end
1054
1048
 
1049
+ procs.zip(all_works).each do |key, workers|
1050
+ workers.each_pair do |tid, json|
1051
+ results << [key, tid, Sidekiq.load_json(json)] unless json.empty?
1052
+ end
1053
+ end
1054
+
1055
1055
  results.sort_by { |(_, _, hsh)| hsh["run_at"] }.each(&block)
1056
1056
  end
1057
1057
 
@@ -4,10 +4,10 @@ module Sidekiq
4
4
  # A Sidekiq::Capsule is the set of resources necessary to
5
5
  # process one or more queues with a given concurrency.
6
6
  # One "default" Capsule is started but the user may declare additional
7
- # Capsules in the initializer.
7
+ # Capsules in their initializer.
8
8
  #
9
- # To process a "single" queue with one thread so jobs are processed
10
- # serially, you can do this:
9
+ # This capsule will pull jobs from the "single" queue and process
10
+ # the jobs with one thread, meaning the jobs will be processed serially.
11
11
  #
12
12
  # Sidekiq.configure_server do |config|
13
13
  # config.capsule("single-threaded") do |cap|
@@ -38,7 +38,7 @@ module Sidekiq
38
38
  end
39
39
 
40
40
  def stop
41
- fetcher&.bulk_requeue([], nil)
41
+ fetcher&.bulk_requeue([])
42
42
  end
43
43
 
44
44
  def queues=(val)
data/lib/sidekiq/cli.rb CHANGED
@@ -280,6 +280,13 @@ module Sidekiq # :nodoc:
280
280
  cap.queues = opts[:queues]
281
281
  cap.concurrency = opts[:concurrency] || @config[:concurrency]
282
282
  end
283
+
284
+ opts[:capsules]&.each do |name, cap_config|
285
+ @config.capsule(name.to_s) do |cap|
286
+ cap.queues = cap_config[:queues]
287
+ cap.concurrency = cap_config[:concurrency]
288
+ end
289
+ end
283
290
  end
284
291
 
285
292
  def boot_application
@@ -339,10 +346,6 @@ module Sidekiq # :nodoc:
339
346
  opts[:concurrency] = Integer(arg)
340
347
  end
341
348
 
342
- o.on "-d", "--daemon", "Daemonize process" do |arg|
343
- puts "ERROR: Daemonization mode was removed in Sidekiq 6.0, please use a proper process supervisor to start and manage your services"
344
- end
345
-
346
349
  o.on "-e", "--environment ENV", "Application environment" do |arg|
347
350
  opts[:environment] = arg
348
351
  end
@@ -372,15 +375,7 @@ module Sidekiq # :nodoc:
372
375
  opts[:config_file] = arg
373
376
  end
374
377
 
375
- o.on "-L", "--logfile PATH", "path to writable logfile" do |arg|
376
- puts "ERROR: Logfile redirection was removed in Sidekiq 6.0, Sidekiq will only log to STDOUT"
377
- end
378
-
379
- o.on "-P", "--pidfile PATH", "path to pidfile" do |arg|
380
- puts "ERROR: PID file creation was removed in Sidekiq 6.0, please use a proper process supervisor to start and manage your services"
381
- end
382
-
383
- o.on "-V", "--version", "Print version and exit" do |arg|
378
+ o.on "-V", "--version", "Print version and exit" do
384
379
  puts "Sidekiq #{Sidekiq::VERSION}"
385
380
  die(0)
386
381
  end
@@ -33,7 +33,8 @@ module Sidekiq
33
33
  reloader: proc { |&block| block.call }
34
34
  }
35
35
 
36
- ERROR_HANDLER = ->(ex, ctx, cfg = Sidekiq.default_configuration) {
36
+ ERROR_HANDLER = ->(ex, ctx) {
37
+ cfg = ctx[:_config] || Sidekiq.default_configuration
37
38
  l = cfg.logger
38
39
  l.warn(Sidekiq.dump_json(ctx)) unless ctx.empty?
39
40
  l.warn("#{ex.class.name}: #{ex.message}")
@@ -49,7 +50,6 @@ module Sidekiq
49
50
  end
50
51
 
51
52
  def_delegators :@options, :[], :[]=, :fetch, :key?, :has_key?, :merge!
52
- attr_reader :options
53
53
  attr_reader :capsules
54
54
 
55
55
  # LEGACY: edits the default capsule
@@ -257,8 +257,9 @@ module Sidekiq
257
257
  if @options[:error_handlers].size == 0
258
258
  p ["!!!!!", ex]
259
259
  end
260
+ ctx[:_config] = self
260
261
  @options[:error_handlers].each do |handler|
261
- handler.call(ex, ctx, self)
262
+ handler.call(ex, ctx)
262
263
  rescue => e
263
264
  l = logger
264
265
  l.error "!!! ERROR HANDLER THREW AN ERROR !!!"
data/lib/sidekiq/fetch.rb CHANGED
@@ -50,7 +50,7 @@ module Sidekiq # :nodoc:
50
50
  UnitOfWork.new(queue, job, config) if queue
51
51
  end
52
52
 
53
- def bulk_requeue(inprogress, _)
53
+ def bulk_requeue(inprogress)
54
54
  return if inprogress.empty?
55
55
 
56
56
  logger.debug { "Re-queueing terminated jobs" }
@@ -104,7 +104,7 @@ module Sidekiq
104
104
  # contract says that jobs are run AT LEAST once. Process termination
105
105
  # is delayed until we're certain the jobs are back in Redis because
106
106
  # it is worse to lose a job than to run it twice.
107
- capsule.fetcher.bulk_requeue(jobs, nil)
107
+ capsule.fetcher.bulk_requeue(jobs)
108
108
  end
109
109
 
110
110
  cleanup.each do |processor|
@@ -43,5 +43,13 @@ module Sidekiq
43
43
  end
44
44
  end
45
45
  end
46
+
47
+ def page_items(items, pageidx = 1, page_size = 25)
48
+ current_page = pageidx.to_i < 1 ? 1 : pageidx.to_i
49
+ pageidx = current_page - 1
50
+ starting = pageidx * page_size
51
+ items = items.to_a
52
+ [current_page, items.size, items[starting, page_size]]
53
+ end
46
54
  end
47
55
  end
data/lib/sidekiq/rails.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "sidekiq/job"
4
+ require "rails"
4
5
 
5
6
  module Sidekiq
6
7
  class Rails < ::Rails::Engine
@@ -22,7 +23,7 @@ module Sidekiq
22
23
 
23
24
  # By including the Options module, we allow AJs to directly control sidekiq features
24
25
  # via the *sidekiq_options* class method and, for instance, not use AJ's retry system.
25
- # AJ retries don't show up in the Sidekiq UI Retries tab, save any error data, can't be
26
+ # AJ retries don't show up in the Sidekiq UI Retries tab, don't save any error data, can't be
26
27
  # manually retried, don't automatically die, etc.
27
28
  #
28
29
  # class SomeJob < ActiveJob::Base
@@ -48,13 +49,6 @@ module Sidekiq
48
49
  end
49
50
  end
50
51
 
51
- config.before_configuration do
52
- dep = ActiveSupport::Deprecation.new("7.0", "Sidekiq")
53
- dep.deprecate_methods(Sidekiq.singleton_class,
54
- default_worker_options: :default_job_options,
55
- "default_worker_options=": :default_job_options=)
56
- end
57
-
58
52
  # This hook happens after all initializers are run, just before returning
59
53
  # from config/environment.rb back to sidekiq/cli.rb.
60
54
  #
@@ -211,7 +211,7 @@ module Sidekiq
211
211
  #
212
212
  # You can also clear and drain all job types:
213
213
  #
214
- # Sidekiq::Worker.clear_all # or .drain_all
214
+ # Sidekiq::Job.clear_all # or .drain_all
215
215
  #
216
216
  # This can be useful to make sure jobs don't linger between tests:
217
217
  #
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sidekiq
4
- VERSION = "7.0.0.beta1"
4
+ VERSION = "7.0.0"
5
+ MAJOR = 7
5
6
  end
@@ -74,6 +74,9 @@ module Sidekiq
74
74
  end
75
75
 
76
76
  get "/busy" do
77
+ @count = (params["count"] || 100).to_i
78
+ (@current_page, @total_size, @workset) = page_items(workset, params["page"], @count)
79
+
77
80
  erb(:busy)
78
81
  end
79
82
 
@@ -148,25 +148,15 @@ module Sidekiq
148
148
  @processes ||= Sidekiq::ProcessSet.new
149
149
  end
150
150
 
151
- # Sorts processes by hostname following the natural sort order so that
152
- # 'worker.1' < 'worker.2' < 'worker.10' < 'worker.20'
153
- # '2.1.1.1' < '192.168.0.2' < '192.168.0.10'
151
+ # Sorts processes by hostname following the natural sort order
154
152
  def sorted_processes
155
153
  @sorted_processes ||= begin
156
154
  return processes unless processes.all? { |p| p["hostname"] }
157
155
 
158
- split_characters = /[._-]+/
159
-
160
- padding = processes.flat_map { |p| p["hostname"].split(split_characters) }.map(&:size).max
161
-
162
156
  processes.to_a.sort_by do |process|
163
- process["hostname"].split(split_characters).map do |substring|
164
- # Left-pad the substring with '0' if it starts with a number or 'a'
165
- # otherwise, so that '25' < 192' < 'a' ('025' < '192' < 'aaa')
166
- padding_char = substring[0].match?(/\d/) ? "0" : "a"
167
-
168
- substring.rjust(padding, padding_char)
169
- end
157
+ # Kudos to `shurikk` on StackOverflow
158
+ # https://stackoverflow.com/a/15170063/575547
159
+ process["hostname"].split(/(\d+)/).map { |a| /\d+/.match?(a) ? a.to_i : a }
170
160
  end
171
161
  end
172
162
  end
@@ -1,4 +1,4 @@
1
- require "sidekiq/job"
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Sidekiq
4
4
  # Sidekiq::Job is a new alias for Sidekiq::Worker as of Sidekiq 6.3.0.
data/lib/sidekiq.rb CHANGED
@@ -3,6 +3,30 @@
3
3
  require "sidekiq/version"
4
4
  fail "Sidekiq #{Sidekiq::VERSION} does not support Ruby versions below 2.7.0." if RUBY_PLATFORM != "java" && Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7.0")
5
5
 
6
+ begin
7
+ require "sidekiq-ent/version"
8
+ fail <<~EOM if Gem::Version.new(Sidekiq::Enterprise::VERSION).segments[0] != Sidekiq::MAJOR
9
+
10
+ Sidekiq Enterprise #{Sidekiq::Enterprise::VERSION} does not work with Sidekiq #{Sidekiq::VERSION}.
11
+ Starting with Sidekiq 7, major versions are synchronized so Sidekiq Enterprise 7 works with Sidekiq 7.
12
+ Use `bundle up sidekiq-ent` to upgrade.
13
+
14
+ EOM
15
+ rescue LoadError
16
+ end
17
+
18
+ begin
19
+ require "sidekiq/pro/version"
20
+ fail <<~EOM if Gem::Version.new(Sidekiq::Pro::VERSION).segments[0] != Sidekiq::MAJOR
21
+
22
+ Sidekiq Pro #{Sidekiq::Pro::VERSION} does not work with Sidekiq #{Sidekiq::VERSION}.
23
+ Starting with Sidekiq 7, major versions are synchronized so Sidekiq Pro 7 works with Sidekiq 7.
24
+ Use `bundle up sidekiq-pro` to upgrade.
25
+
26
+ EOM
27
+ rescue LoadError
28
+ end
29
+
6
30
  require "sidekiq/config"
7
31
  require "sidekiq/logger"
8
32
  require "sidekiq/client"
@@ -80,7 +104,7 @@ module Sidekiq
80
104
  end
81
105
 
82
106
  # Creates a Sidekiq::Config instance that is more tuned for embedding
83
- # within an arbitrary Ruby process. Noteably it reduces concurrency by
107
+ # within an arbitrary Ruby process. Notably it reduces concurrency by
84
108
  # default so there is less contention for CPU time with other threads.
85
109
  #
86
110
  # inst = Sidekiq.configure_embed do |config|
data/sidekiq.gemspec CHANGED
@@ -44,7 +44,7 @@ Gem::Specification.new do |gem|
44
44
  WARNING: This is a beta release, expect breakage!
45
45
 
46
46
  1. Use `gem 'sidekiq', '<7'` in your Gemfile if you don't want to be a beta tester.
47
- 2. Read the release notes at https://github.com/mperham/sidekiq/blob/7-0/docs/7.0-Upgrade.md
47
+ 2. Read the release notes at https://github.com/mperham/sidekiq/blob/main/docs/7.0-Upgrade.md
48
48
  3. Search for open/closed issues at https://github.com/mperham/sidekiq/issues/
49
49
 
50
50
  ####################################################
data/web/views/busy.erb CHANGED
@@ -96,6 +96,11 @@
96
96
  <div class="col-sm-7">
97
97
  <h3><%= t('Jobs') %></h3>
98
98
  </div>
99
+ <% if @workset.size > 0 && @total_size > @count %>
100
+ <div class="col-sm-4">
101
+ <%= erb :_paging, locals: { url: "#{root_path}busy" } %>
102
+ </div>
103
+ <% end %>
99
104
  </div>
100
105
 
101
106
  <div class="table_container">
@@ -109,7 +114,7 @@
109
114
  <th><%= t('Arguments') %></th>
110
115
  <th><%= t('Started') %></th>
111
116
  </thead>
112
- <% workset.each do |process, thread, msg| %>
117
+ <% @workset.each do |process, thread, msg| %>
113
118
  <% job = Sidekiq::JobRecord.new(msg['payload']) %>
114
119
  <tr>
115
120
  <td><%= process %></td>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0.beta1
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Perham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-26 00:00:00.000000000 Z
11
+ date: 2022-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-client
@@ -111,7 +111,6 @@ files:
111
111
  - lib/sidekiq/middleware/modules.rb
112
112
  - lib/sidekiq/monitor.rb
113
113
  - lib/sidekiq/paginator.rb
114
- - lib/sidekiq/pool.rb
115
114
  - lib/sidekiq/processor.rb
116
115
  - lib/sidekiq/rails.rb
117
116
  - lib/sidekiq/redis_client_adapter.rb
@@ -223,7 +222,7 @@ post_install_message: |2
223
222
  WARNING: This is a beta release, expect breakage!
224
223
 
225
224
  1. Use `gem 'sidekiq', '<7'` in your Gemfile if you don't want to be a beta tester.
226
- 2. Read the release notes at https://github.com/mperham/sidekiq/blob/7-0/docs/7.0-Upgrade.md
225
+ 2. Read the release notes at https://github.com/mperham/sidekiq/blob/main/docs/7.0-Upgrade.md
227
226
  3. Search for open/closed issues at https://github.com/mperham/sidekiq/issues/
228
227
 
229
228
  ####################################################
@@ -237,9 +236,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
237
236
  version: 2.7.0
238
237
  required_rubygems_version: !ruby/object:Gem::Requirement
239
238
  requirements:
240
- - - ">"
239
+ - - ">="
241
240
  - !ruby/object:Gem::Version
242
- version: 1.3.1
241
+ version: '0'
243
242
  requirements: []
244
243
  rubygems_version: 3.2.32
245
244
  signing_key:
data/lib/sidekiq/pool.rb DELETED
@@ -1,7 +0,0 @@
1
- module Sidekiq
2
- module PoolAccess
3
- def redis_pool
4
- Thread.current[:sidekiq_redis_pool] || (@redis ||= Sidekiq::RedisConnection.create)
5
- end
6
- end
7
- end