sidekiq 6.1.3 → 6.3.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 +4 -4
- data/Changes.md +89 -1
- data/LICENSE +1 -1
- data/README.md +2 -2
- data/lib/sidekiq/api.rb +92 -56
- data/lib/sidekiq/cli.rb +10 -2
- data/lib/sidekiq/client.rb +2 -6
- data/lib/sidekiq/extensions/generic_proxy.rb +3 -1
- data/lib/sidekiq/fetch.rb +13 -4
- data/lib/sidekiq/job.rb +13 -0
- data/lib/sidekiq/job_logger.rb +1 -1
- data/lib/sidekiq/job_retry.rb +3 -7
- data/lib/sidekiq/launcher.rb +50 -18
- data/lib/sidekiq/middleware/chain.rb +5 -3
- data/lib/sidekiq/middleware/current_attributes.rb +48 -0
- data/lib/sidekiq/rails.rb +11 -0
- data/lib/sidekiq/redis_connection.rb +4 -6
- data/lib/sidekiq/scheduled.rb +40 -15
- data/lib/sidekiq/testing.rb +1 -3
- data/lib/sidekiq/util.rb +28 -0
- data/lib/sidekiq/version.rb +1 -1
- data/lib/sidekiq/web/action.rb +2 -2
- data/lib/sidekiq/web/application.rb +14 -6
- data/lib/sidekiq/web/csrf_protection.rb +25 -1
- data/lib/sidekiq/web/helpers.rb +22 -25
- data/lib/sidekiq/web/router.rb +4 -1
- data/lib/sidekiq/web.rb +34 -78
- data/lib/sidekiq/worker.rb +72 -5
- data/lib/sidekiq.rb +3 -1
- data/sidekiq.gemspec +9 -1
- data/web/assets/images/apple-touch-icon.png +0 -0
- data/web/assets/javascripts/application.js +82 -61
- data/web/assets/javascripts/dashboard.js +51 -51
- data/web/assets/stylesheets/application-dark.css +21 -23
- data/web/assets/stylesheets/application-rtl.css +0 -4
- data/web/assets/stylesheets/application.css +28 -237
- data/web/locales/ar.yml +8 -2
- data/web/locales/en.yml +4 -1
- data/web/locales/es.yml +18 -2
- data/web/locales/fr.yml +7 -0
- data/web/locales/ja.yml +3 -0
- data/web/locales/lt.yml +1 -1
- data/web/views/_footer.erb +1 -1
- data/web/views/_job_info.erb +1 -1
- data/web/views/_poll_link.erb +2 -5
- data/web/views/_summary.erb +7 -7
- data/web/views/busy.erb +47 -18
- data/web/views/dashboard.erb +22 -14
- data/web/views/dead.erb +1 -1
- data/web/views/layout.erb +2 -1
- data/web/views/morgue.erb +6 -6
- data/web/views/queue.erb +11 -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 +11 -24
- 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 -309
- data/Gemfile +0 -24
- data/Gemfile.lock +0 -193
- 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 -813
- data/Rakefile +0 -10
- data/code_of_conduct.md +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b72b92d3d281aaea2b4781cb7743d95a8c7f42708526383bf85fbed420b4b82c
|
4
|
+
data.tar.gz: 9546107658b47c8f68497730e2ee6689881c1388ba96db3f2415b0fda7b7f668
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78f0af1f4ed41c5b4ad01636d9808d409d1cedc0bc6146be278412e87f9d826fad2cec9c89b31acbc6da9bab59bff44e826418991b10ce27b34631bcc3a00cf2
|
7
|
+
data.tar.gz: a586b9ec613cf3da47ecb77eb4e0f5d6e497f234369d958cdfa3d8c8c7418806383e022a9b08db4c3b5d08a1c2aac3aaecdf851744234f4c42055e1a7a6ebf6c
|
data/Changes.md
CHANGED
@@ -1,6 +1,94 @@
|
|
1
1
|
# Sidekiq Changes
|
2
2
|
|
3
|
-
[Sidekiq Changes](https://github.com/mperham/sidekiq/blob/
|
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
|
+
|
5
|
+
HEAD
|
6
|
+
---------
|
7
|
+
|
8
|
+
- **BREAK**: The Web UI has been refactored to remove jQuery. Any UI extensions
|
9
|
+
which use jQuery will break.
|
10
|
+
- **FEATURE**: Sidekiq.logger has been enhanced so any `Rails.logger`
|
11
|
+
output in jobs now shows up in the Sidekiq console. Remove any logger
|
12
|
+
hacks in your initializer and see if it Just Works™ now. [#5021]
|
13
|
+
- **FEATURE**: Add `Sidekiq::Job` alias for `Sidekiq::Worker`, to better
|
14
|
+
reflect industry standard terminology. You can now do this:
|
15
|
+
```ruby
|
16
|
+
class MyJob
|
17
|
+
include Sidekiq::Job
|
18
|
+
sidekiq_options ...
|
19
|
+
def perform(args)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
```
|
23
|
+
- **FEATURE**: Support for serializing ActiveSupport::CurrentAttributes into each job. [#4982]
|
24
|
+
```ruby
|
25
|
+
# config/initializers/sidekiq.rb
|
26
|
+
require "sidekiq/middleware/current_attributes"
|
27
|
+
Sidekiq::CurrentAttributes.persist(Myapp::Current) # Your AS::CurrentAttributes singleton
|
28
|
+
```
|
29
|
+
- **FEATURE**: Add `Sidekiq::Worker.perform_bulk` for enqueuing jobs in bulk,
|
30
|
+
similar to `Sidekiq::Client.push_bulk` [#5042]
|
31
|
+
```ruby
|
32
|
+
MyJob.perform_bulk([[1], [2], [3]])
|
33
|
+
```
|
34
|
+
- Implement `queue_as`, `wait` and `wait_until` for ActiveJob compatibility [#5003]
|
35
|
+
- Scheduler now uses Lua to reduce Redis load and network roundtrips [#5044]
|
36
|
+
- Retry Redis operation if we get an `UNBLOCKED` Redis error [#4985]
|
37
|
+
- Run existing signal traps, if any, before running Sidekiq's trap [#4991]
|
38
|
+
- Fix fetch bug when using weighted queues which caused Sidekiq to stop
|
39
|
+
processing queues randomly [#5031]
|
40
|
+
|
41
|
+
6.2.2
|
42
|
+
---------
|
43
|
+
|
44
|
+
- Reduce retry jitter, add jitter to `sidekiq_retry_in` values [#4957]
|
45
|
+
- Minimize scheduler load on Redis at scale [#4882]
|
46
|
+
- Improve logging of delay jobs [#4904, BuonOno]
|
47
|
+
- Minor CSS improvements for buttons and tables, design PRs always welcome!
|
48
|
+
- Tweak Web UI `Cache-Control` header [#4966]
|
49
|
+
- Rename internal API class `Sidekiq::Job` to `Sidekiq::JobRecord` [#4955]
|
50
|
+
|
51
|
+
6.2.1
|
52
|
+
---------
|
53
|
+
|
54
|
+
- Update RTT warning logic to handle transient RTT spikes [#4851]
|
55
|
+
- Fix very low priority CVE on unescaped queue name [#4852]
|
56
|
+
- Add note about sessions and Rails apps in API mode
|
57
|
+
|
58
|
+
6.2.0
|
59
|
+
---------
|
60
|
+
|
61
|
+
- Store Redis RTT and log if poor [#4824]
|
62
|
+
- Add process/thread stats to Busy page [#4806]
|
63
|
+
- Improve Web UI on mobile devices [#4840]
|
64
|
+
- **Refactor Web UI session usage** [#4804]
|
65
|
+
Numerous people have hit "Forbidden" errors and struggled with Sidekiq's
|
66
|
+
Web UI session requirement. If you have code in your initializer for
|
67
|
+
Web sessions, it's quite possible it will need to be removed. Here's
|
68
|
+
an overview:
|
69
|
+
```
|
70
|
+
Sidekiq::Web needs a valid Rack session for CSRF protection. If this is a Rails app,
|
71
|
+
make sure you mount Sidekiq::Web *inside* your routes in `config/routes.rb` so
|
72
|
+
Sidekiq can reuse the Rails session:
|
73
|
+
|
74
|
+
Rails.application.routes.draw do
|
75
|
+
mount Sidekiq::Web => "/sidekiq"
|
76
|
+
....
|
77
|
+
end
|
78
|
+
|
79
|
+
If this is a bare Rack app, use a session middleware before Sidekiq::Web:
|
80
|
+
|
81
|
+
# first, use IRB to create a shared secret key for sessions and commit it
|
82
|
+
require 'securerandom'; File.open(".session.key", "w") {|f| f.write(SecureRandom.hex(32)) }
|
83
|
+
|
84
|
+
# now, update your Rack app to include the secret with a session cookie middleware
|
85
|
+
use Rack::Session::Cookie, secret: File.read(".session.key"), same_site: true, max_age: 86400
|
86
|
+
run Sidekiq::Web
|
87
|
+
|
88
|
+
If this is a Rails app in API mode, you need to enable sessions.
|
89
|
+
|
90
|
+
https://guides.rubyonrails.org/api_app.html#using-session-middlewares
|
91
|
+
```
|
4
92
|
|
5
93
|
6.1.3
|
6
94
|
---------
|
data/LICENSE
CHANGED
@@ -6,4 +6,4 @@ for license text.
|
|
6
6
|
|
7
7
|
Sidekiq Pro has a commercial-friendly license allowing private forks
|
8
8
|
and modifications of Sidekiq. Please see https://sidekiq.org/products/pro.html for
|
9
|
-
more detail. You can find the commercial license terms in COMM-LICENSE.
|
9
|
+
more detail. You can find the commercial license terms in COMM-LICENSE.txt.
|
data/README.md
CHANGED
@@ -46,7 +46,7 @@ See the [Getting Started wiki page](https://github.com/mperham/sidekiq/wiki/Gett
|
|
46
46
|
You can watch [this Youtube playlist](https://www.youtube.com/playlist?list=PLjeHh2LSCFrWGT5uVjUuFKAcrcj5kSai1) to learn all about
|
47
47
|
Sidekiq and see its features in action. Here's the Web UI:
|
48
48
|
|
49
|
-
![Web UI](https://github.com/mperham/sidekiq/raw/
|
49
|
+
![Web UI](https://github.com/mperham/sidekiq/raw/main/examples/web-ui.png)
|
50
50
|
|
51
51
|
|
52
52
|
Want to Upgrade?
|
@@ -84,7 +84,7 @@ See the [Sidekiq support page](https://sidekiq.org/support.html) for details.
|
|
84
84
|
License
|
85
85
|
-----------------
|
86
86
|
|
87
|
-
Please see [LICENSE](https://github.com/mperham/sidekiq/blob/
|
87
|
+
Please see [LICENSE](https://github.com/mperham/sidekiq/blob/main/LICENSE) for licensing details.
|
88
88
|
|
89
89
|
|
90
90
|
Author
|
data/lib/sidekiq/api.rb
CHANGED
@@ -8,7 +8,7 @@ require "base64"
|
|
8
8
|
module Sidekiq
|
9
9
|
class Stats
|
10
10
|
def initialize
|
11
|
-
|
11
|
+
fetch_stats_fast!
|
12
12
|
end
|
13
13
|
|
14
14
|
def processed
|
@@ -51,7 +51,8 @@ module Sidekiq
|
|
51
51
|
Sidekiq::Stats::Queues.new.lengths
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
# O(1) redis calls
|
55
|
+
def fetch_stats_fast!
|
55
56
|
pipe1_res = Sidekiq.redis { |conn|
|
56
57
|
conn.pipelined do
|
57
58
|
conn.get("stat:processed")
|
@@ -64,25 +65,6 @@ module Sidekiq
|
|
64
65
|
end
|
65
66
|
}
|
66
67
|
|
67
|
-
processes = Sidekiq.redis { |conn|
|
68
|
-
conn.sscan_each("processes").to_a
|
69
|
-
}
|
70
|
-
|
71
|
-
queues = Sidekiq.redis { |conn|
|
72
|
-
conn.sscan_each("queues").to_a
|
73
|
-
}
|
74
|
-
|
75
|
-
pipe2_res = Sidekiq.redis { |conn|
|
76
|
-
conn.pipelined do
|
77
|
-
processes.each { |key| conn.hget(key, "busy") }
|
78
|
-
queues.each { |queue| conn.llen("queue:#{queue}") }
|
79
|
-
end
|
80
|
-
}
|
81
|
-
|
82
|
-
s = processes.size
|
83
|
-
workers_size = pipe2_res[0...s].sum(&:to_i)
|
84
|
-
enqueued = pipe2_res[s..-1].sum(&:to_i)
|
85
|
-
|
86
68
|
default_queue_latency = if (entry = pipe1_res[6].first)
|
87
69
|
job = begin
|
88
70
|
Sidekiq.load_json(entry)
|
@@ -95,6 +77,7 @@ module Sidekiq
|
|
95
77
|
else
|
96
78
|
0
|
97
79
|
end
|
80
|
+
|
98
81
|
@stats = {
|
99
82
|
processed: pipe1_res[0].to_i,
|
100
83
|
failed: pipe1_res[1].to_i,
|
@@ -103,10 +86,39 @@ module Sidekiq
|
|
103
86
|
dead_size: pipe1_res[4],
|
104
87
|
processes_size: pipe1_res[5],
|
105
88
|
|
106
|
-
default_queue_latency: default_queue_latency
|
107
|
-
|
108
|
-
|
89
|
+
default_queue_latency: default_queue_latency
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
# O(number of processes + number of queues) redis calls
|
94
|
+
def fetch_stats_slow!
|
95
|
+
processes = Sidekiq.redis { |conn|
|
96
|
+
conn.sscan_each("processes").to_a
|
97
|
+
}
|
98
|
+
|
99
|
+
queues = Sidekiq.redis { |conn|
|
100
|
+
conn.sscan_each("queues").to_a
|
101
|
+
}
|
102
|
+
|
103
|
+
pipe2_res = Sidekiq.redis { |conn|
|
104
|
+
conn.pipelined do
|
105
|
+
processes.each { |key| conn.hget(key, "busy") }
|
106
|
+
queues.each { |queue| conn.llen("queue:#{queue}") }
|
107
|
+
end
|
109
108
|
}
|
109
|
+
|
110
|
+
s = processes.size
|
111
|
+
workers_size = pipe2_res[0...s].sum(&:to_i)
|
112
|
+
enqueued = pipe2_res[s..-1].sum(&:to_i)
|
113
|
+
|
114
|
+
@stats[:workers_size] = workers_size
|
115
|
+
@stats[:enqueued] = enqueued
|
116
|
+
@stats
|
117
|
+
end
|
118
|
+
|
119
|
+
def fetch_stats!
|
120
|
+
fetch_stats_fast!
|
121
|
+
fetch_stats_slow!
|
110
122
|
end
|
111
123
|
|
112
124
|
def reset(*stats)
|
@@ -126,7 +138,8 @@ module Sidekiq
|
|
126
138
|
private
|
127
139
|
|
128
140
|
def stat(s)
|
129
|
-
@stats[s]
|
141
|
+
fetch_stats_slow! if @stats[s].nil?
|
142
|
+
@stats[s] || raise(ArgumentError, "Unknown stat #{s}")
|
130
143
|
end
|
131
144
|
|
132
145
|
class Queues
|
@@ -141,7 +154,7 @@ module Sidekiq
|
|
141
154
|
}
|
142
155
|
|
143
156
|
array_of_arrays = queues.zip(lengths).sort_by { |_, size| -size }
|
144
|
-
|
157
|
+
array_of_arrays.to_h
|
145
158
|
end
|
146
159
|
end
|
147
160
|
end
|
@@ -255,7 +268,7 @@ module Sidekiq
|
|
255
268
|
break if entries.empty?
|
256
269
|
page += 1
|
257
270
|
entries.each do |entry|
|
258
|
-
yield
|
271
|
+
yield JobRecord.new(entry, @name)
|
259
272
|
end
|
260
273
|
deleted_size = initial_size - size
|
261
274
|
end
|
@@ -265,7 +278,7 @@ module Sidekiq
|
|
265
278
|
# Find the job with the given JID within this queue.
|
266
279
|
#
|
267
280
|
# This is a slow, inefficient operation. Do not use under
|
268
|
-
# normal conditions.
|
281
|
+
# normal conditions.
|
269
282
|
def find_job(jid)
|
270
283
|
detect { |j| j.jid == jid }
|
271
284
|
end
|
@@ -286,9 +299,9 @@ module Sidekiq
|
|
286
299
|
# sorted set.
|
287
300
|
#
|
288
301
|
# The job should be considered immutable but may be
|
289
|
-
# removed from the queue via
|
302
|
+
# removed from the queue via JobRecord#delete.
|
290
303
|
#
|
291
|
-
class
|
304
|
+
class JobRecord
|
292
305
|
attr_reader :item
|
293
306
|
attr_reader :value
|
294
307
|
|
@@ -316,21 +329,23 @@ module Sidekiq
|
|
316
329
|
|
317
330
|
def display_class
|
318
331
|
# Unwrap known wrappers so they show up in a human-friendly manner in the Web UI
|
319
|
-
@klass ||=
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
332
|
+
@klass ||= self["display_class"] || begin
|
333
|
+
case klass
|
334
|
+
when /\ASidekiq::Extensions::Delayed/
|
335
|
+
safe_load(args[0], klass) do |target, method, _|
|
336
|
+
"#{target}.#{method}"
|
337
|
+
end
|
338
|
+
when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"
|
339
|
+
job_class = @item["wrapped"] || args[0]
|
340
|
+
if job_class == "ActionMailer::DeliveryJob" || job_class == "ActionMailer::MailDeliveryJob"
|
341
|
+
# MailerClass#mailer_method
|
342
|
+
args[0]["arguments"][0..1].join("#")
|
343
|
+
else
|
344
|
+
job_class
|
345
|
+
end
|
346
|
+
else
|
347
|
+
klass
|
348
|
+
end
|
334
349
|
end
|
335
350
|
end
|
336
351
|
|
@@ -443,7 +458,7 @@ module Sidekiq
|
|
443
458
|
end
|
444
459
|
end
|
445
460
|
|
446
|
-
class SortedEntry <
|
461
|
+
class SortedEntry < JobRecord
|
447
462
|
attr_reader :score
|
448
463
|
attr_reader :parent
|
449
464
|
|
@@ -791,12 +806,12 @@ module Sidekiq
|
|
791
806
|
# you'll be happier this way
|
792
807
|
conn.pipelined do
|
793
808
|
procs.each do |key|
|
794
|
-
conn.hmget(key, "info", "busy", "beat", "quiet", "rss")
|
809
|
+
conn.hmget(key, "info", "busy", "beat", "quiet", "rss", "rtt_us")
|
795
810
|
end
|
796
811
|
end
|
797
812
|
}
|
798
813
|
|
799
|
-
result.each do |info, busy, at_s, quiet, rss|
|
814
|
+
result.each do |info, busy, at_s, quiet, rss, rtt|
|
800
815
|
# If a process is stopped between when we query Redis for `procs` and
|
801
816
|
# when we query for `result`, we will have an item in `result` that is
|
802
817
|
# composed of `nil` values.
|
@@ -806,7 +821,8 @@ module Sidekiq
|
|
806
821
|
yield Process.new(hash.merge("busy" => busy.to_i,
|
807
822
|
"beat" => at_s.to_f,
|
808
823
|
"quiet" => quiet,
|
809
|
-
"rss" => rss
|
824
|
+
"rss" => rss.to_i,
|
825
|
+
"rtt_us" => rtt.to_i))
|
810
826
|
end
|
811
827
|
end
|
812
828
|
|
@@ -818,6 +834,18 @@ module Sidekiq
|
|
818
834
|
Sidekiq.redis { |conn| conn.scard("processes") }
|
819
835
|
end
|
820
836
|
|
837
|
+
# Total number of threads available to execute jobs.
|
838
|
+
# For Sidekiq Enterprise customers this number (in production) must be
|
839
|
+
# less than or equal to your licensed concurrency.
|
840
|
+
def total_concurrency
|
841
|
+
sum { |x| x["concurrency"].to_i }
|
842
|
+
end
|
843
|
+
|
844
|
+
def total_rss_in_kb
|
845
|
+
sum { |x| x["rss"].to_i }
|
846
|
+
end
|
847
|
+
alias_method :total_rss, :total_rss_in_kb
|
848
|
+
|
821
849
|
# Returns the identity of the current cluster leader or "" if no leader.
|
822
850
|
# This is a Sidekiq Enterprise feature, will always return "" in Sidekiq
|
823
851
|
# or Sidekiq Pro.
|
@@ -867,6 +895,10 @@ module Sidekiq
|
|
867
895
|
self["identity"]
|
868
896
|
end
|
869
897
|
|
898
|
+
def queues
|
899
|
+
self["queues"]
|
900
|
+
end
|
901
|
+
|
870
902
|
def quiet!
|
871
903
|
signal("TSTP")
|
872
904
|
end
|
@@ -897,8 +929,8 @@ module Sidekiq
|
|
897
929
|
end
|
898
930
|
|
899
931
|
##
|
900
|
-
#
|
901
|
-
#
|
932
|
+
# The WorkSet stores the work being done by this Sidekiq cluster.
|
933
|
+
# It tracks the process and thread working on each job.
|
902
934
|
#
|
903
935
|
# WARNING WARNING WARNING
|
904
936
|
#
|
@@ -906,17 +938,17 @@ module Sidekiq
|
|
906
938
|
# If you call #size => 5 and then expect #each to be
|
907
939
|
# called 5 times, you're going to have a bad time.
|
908
940
|
#
|
909
|
-
#
|
910
|
-
#
|
911
|
-
#
|
941
|
+
# works = Sidekiq::WorkSet.new
|
942
|
+
# works.size => 2
|
943
|
+
# works.each do |process_id, thread_id, work|
|
912
944
|
# # process_id is a unique identifier per Sidekiq process
|
913
945
|
# # thread_id is a unique identifier per thread
|
914
946
|
# # work is a Hash which looks like:
|
915
|
-
# # { 'queue' => name, 'run_at' => timestamp, 'payload' =>
|
947
|
+
# # { 'queue' => name, 'run_at' => timestamp, 'payload' => job_hash }
|
916
948
|
# # run_at is an epoch Integer.
|
917
949
|
# end
|
918
950
|
#
|
919
|
-
class
|
951
|
+
class WorkSet
|
920
952
|
include Enumerable
|
921
953
|
|
922
954
|
def each(&block)
|
@@ -963,4 +995,8 @@ module Sidekiq
|
|
963
995
|
end
|
964
996
|
end
|
965
997
|
end
|
998
|
+
# Since "worker" is a nebulous term, we've deprecated the use of this class name.
|
999
|
+
# Is "worker" a process, a type of job, a thread? Undefined!
|
1000
|
+
# WorkSet better describes the data.
|
1001
|
+
Workers = WorkSet
|
966
1002
|
end
|
data/lib/sidekiq/cli.rb
CHANGED
@@ -46,7 +46,15 @@ module Sidekiq
|
|
46
46
|
# USR1 and USR2 don't work on the JVM
|
47
47
|
sigs << "USR2" if Sidekiq.pro? && !jruby?
|
48
48
|
sigs.each do |sig|
|
49
|
-
trap
|
49
|
+
old_handler = Signal.trap(sig) do
|
50
|
+
if old_handler.respond_to?(:call)
|
51
|
+
begin
|
52
|
+
old_handler.call
|
53
|
+
rescue Exception => exc
|
54
|
+
# signal handlers can't use Logger so puts only
|
55
|
+
puts ["Error in #{sig} handler", exc].inspect
|
56
|
+
end
|
57
|
+
end
|
50
58
|
self_write.puts(sig)
|
51
59
|
end
|
52
60
|
rescue ArgumentError
|
@@ -396,7 +404,7 @@ module Sidekiq
|
|
396
404
|
opts[:queues] ||= []
|
397
405
|
opts[:strict] = true if opts[:strict].nil?
|
398
406
|
raise ArgumentError, "queues: #{queue} cannot be defined twice" if opts[:queues].include?(queue)
|
399
|
-
[weight.to_i, 1].max.times { opts[:queues] << queue }
|
407
|
+
[weight.to_i, 1].max.times { opts[:queues] << queue.to_s }
|
400
408
|
opts[:strict] = false if weight.to_i > 0
|
401
409
|
end
|
402
410
|
|
data/lib/sidekiq/client.rb
CHANGED
@@ -95,7 +95,7 @@ module Sidekiq
|
|
95
95
|
return [] if args.empty? # no jobs to push
|
96
96
|
|
97
97
|
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))
|
98
|
+
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
99
|
raise ArgumentError, "Job 'at' Array must have same size as 'args' Array" if at.is_a?(Array) && at.size != args.size
|
100
100
|
|
101
101
|
normed = normalize_item(items)
|
@@ -186,7 +186,7 @@ module Sidekiq
|
|
186
186
|
|
187
187
|
def raw_push(payloads)
|
188
188
|
@redis_pool.with do |conn|
|
189
|
-
conn.
|
189
|
+
conn.pipelined do
|
190
190
|
atomic_push(conn, payloads)
|
191
191
|
end
|
192
192
|
end
|
@@ -228,10 +228,6 @@ module Sidekiq
|
|
228
228
|
end
|
229
229
|
|
230
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
231
|
validate(item)
|
236
232
|
# 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
233
|
|
@@ -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
|
data/lib/sidekiq/fetch.rb
CHANGED
@@ -36,7 +36,15 @@ module Sidekiq
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def retrieve_work
|
39
|
-
|
39
|
+
qs = queues_cmd
|
40
|
+
# 4825 Sidekiq Pro with all queues paused will return an
|
41
|
+
# empty set of queues with a trailing TIMEOUT value.
|
42
|
+
if qs.size <= 1
|
43
|
+
sleep(TIMEOUT)
|
44
|
+
return nil
|
45
|
+
end
|
46
|
+
|
47
|
+
work = Sidekiq.redis { |conn| conn.brpop(*qs) }
|
40
48
|
UnitOfWork.new(*work) if work
|
41
49
|
end
|
42
50
|
|
@@ -71,9 +79,10 @@ module Sidekiq
|
|
71
79
|
if @strictly_ordered_queues
|
72
80
|
@queues
|
73
81
|
else
|
74
|
-
|
75
|
-
|
76
|
-
|
82
|
+
permute = @queues.shuffle
|
83
|
+
permute.uniq!
|
84
|
+
permute << TIMEOUT
|
85
|
+
permute
|
77
86
|
end
|
78
87
|
end
|
79
88
|
end
|
data/lib/sidekiq/job.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "sidekiq/worker"
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
# Sidekiq::Job is a new alias for Sidekiq::Worker as of Sidekiq 6.3.0.
|
5
|
+
# Use `include Sidekiq::Job` rather than `include Sidekiq::Worker`.
|
6
|
+
#
|
7
|
+
# The term "worker" is too generic and overly confusing, used in several
|
8
|
+
# different contexts meaning different things. Many people call a Sidekiq
|
9
|
+
# process a "worker". Some people call the thread that executes jobs a
|
10
|
+
# "worker". This change brings Sidekiq closer to ActiveJob where your job
|
11
|
+
# classes extend ApplicationJob.
|
12
|
+
Job = Worker
|
13
|
+
end
|
data/lib/sidekiq/job_logger.rb
CHANGED
@@ -38,7 +38,7 @@ module Sidekiq
|
|
38
38
|
# If we're using a wrapper class, like ActiveJob, use the "wrapped"
|
39
39
|
# attribute to expose the underlying thing.
|
40
40
|
h = {
|
41
|
-
class: job_hash["wrapped"] || job_hash["class"],
|
41
|
+
class: job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"],
|
42
42
|
jid: job_hash["jid"]
|
43
43
|
}
|
44
44
|
h[:bid] = job_hash["bid"] if job_hash["bid"]
|
data/lib/sidekiq/job_retry.rb
CHANGED
@@ -214,16 +214,12 @@ module Sidekiq
|
|
214
214
|
end
|
215
215
|
|
216
216
|
def delay_for(worker, count, exception)
|
217
|
+
jitter = rand(10) * (count + 1)
|
217
218
|
if worker&.sidekiq_retry_in_block
|
218
219
|
custom_retry_in = retry_in(worker, count, exception).to_i
|
219
|
-
return custom_retry_in if custom_retry_in > 0
|
220
|
+
return custom_retry_in + jitter if custom_retry_in > 0
|
220
221
|
end
|
221
|
-
|
222
|
-
end
|
223
|
-
|
224
|
-
# delayed_job uses the same basic formula
|
225
|
-
def seconds_to_delay(count)
|
226
|
-
(count**4) + 15 + (rand(30) * (count + 1))
|
222
|
+
(count**4) + 15 + jitter
|
227
223
|
end
|
228
224
|
|
229
225
|
def retry_in(worker, count, exception)
|
data/lib/sidekiq/launcher.rb
CHANGED
@@ -69,10 +69,12 @@ module Sidekiq
|
|
69
69
|
|
70
70
|
private unless $TESTING
|
71
71
|
|
72
|
+
BEAT_PAUSE = 5
|
73
|
+
|
72
74
|
def start_heartbeat
|
73
75
|
loop do
|
74
76
|
heartbeat
|
75
|
-
sleep
|
77
|
+
sleep BEAT_PAUSE
|
76
78
|
end
|
77
79
|
Sidekiq.logger.info("Heartbeat stopping...")
|
78
80
|
end
|
@@ -153,6 +155,8 @@ module Sidekiq
|
|
153
155
|
end
|
154
156
|
end
|
155
157
|
|
158
|
+
rtt = check_rtt
|
159
|
+
|
156
160
|
fails = procd = 0
|
157
161
|
kb = memory_usage(::Process.pid)
|
158
162
|
|
@@ -163,6 +167,7 @@ module Sidekiq
|
|
163
167
|
conn.hmset(key, "info", to_json,
|
164
168
|
"busy", curstate.size,
|
165
169
|
"beat", Time.now.to_f,
|
170
|
+
"rtt_us", rtt,
|
166
171
|
"quiet", @done,
|
167
172
|
"rss", kb)
|
168
173
|
conn.expire(key, 60)
|
@@ -185,6 +190,37 @@ module Sidekiq
|
|
185
190
|
end
|
186
191
|
end
|
187
192
|
|
193
|
+
# We run the heartbeat every five seconds.
|
194
|
+
# Capture five samples of RTT, log a warning if each sample
|
195
|
+
# is above our warning threshold.
|
196
|
+
RTT_READINGS = RingBuffer.new(5)
|
197
|
+
RTT_WARNING_LEVEL = 50_000
|
198
|
+
|
199
|
+
def check_rtt
|
200
|
+
a = b = 0
|
201
|
+
Sidekiq.redis do |x|
|
202
|
+
a = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond)
|
203
|
+
x.ping
|
204
|
+
b = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond)
|
205
|
+
end
|
206
|
+
rtt = b - a
|
207
|
+
RTT_READINGS << rtt
|
208
|
+
# Ideal RTT for Redis is < 1000µs
|
209
|
+
# Workable is < 10,000µs
|
210
|
+
# Log a warning if it's a disaster.
|
211
|
+
if RTT_READINGS.all? { |x| x > RTT_WARNING_LEVEL }
|
212
|
+
Sidekiq.logger.warn <<~EOM
|
213
|
+
Your Redis network connection is performing extremely poorly.
|
214
|
+
Last RTT readings were #{RTT_READINGS.buffer.inspect}, ideally these should be < 1000.
|
215
|
+
Ensure Redis is running in the same AZ or datacenter as Sidekiq.
|
216
|
+
If these values are close to 100,000, that means your Sidekiq process may be
|
217
|
+
CPU overloaded; see https://github.com/mperham/sidekiq/discussions/5039
|
218
|
+
EOM
|
219
|
+
RTT_READINGS.reset
|
220
|
+
end
|
221
|
+
rtt
|
222
|
+
end
|
223
|
+
|
188
224
|
MEMORY_GRABBER = case RUBY_PLATFORM
|
189
225
|
when /linux/
|
190
226
|
->(pid) {
|
@@ -206,26 +242,22 @@ module Sidekiq
|
|
206
242
|
end
|
207
243
|
|
208
244
|
def to_data
|
209
|
-
@data ||=
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
}
|
220
|
-
end
|
245
|
+
@data ||= {
|
246
|
+
"hostname" => hostname,
|
247
|
+
"started_at" => Time.now.to_f,
|
248
|
+
"pid" => ::Process.pid,
|
249
|
+
"tag" => @options[:tag] || "",
|
250
|
+
"concurrency" => @options[:concurrency],
|
251
|
+
"queues" => @options[:queues].uniq,
|
252
|
+
"labels" => @options[:labels],
|
253
|
+
"identity" => identity
|
254
|
+
}
|
221
255
|
end
|
222
256
|
|
223
257
|
def to_json
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
Sidekiq.dump_json(to_data)
|
228
|
-
end
|
258
|
+
# this data changes infrequently so dump it to a string
|
259
|
+
# now so we don't need to dump it every heartbeat.
|
260
|
+
@json ||= Sidekiq.dump_json(to_data)
|
229
261
|
end
|
230
262
|
end
|
231
263
|
end
|