sidekiq 8.1.6 → 8.1.8
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.
- checksums.yaml +4 -4
- data/Changes.md +18 -0
- data/README.md +5 -3
- data/bin/sidekiqload +2 -0
- data/lib/active_job/queue_adapters/sidekiq_adapter.rb +1 -1
- data/lib/sidekiq/api.rb +16 -13
- data/lib/sidekiq/cli.rb +5 -2
- data/lib/sidekiq/client.rb +3 -3
- data/lib/sidekiq/config.rb +26 -1
- data/lib/sidekiq/embedded.rb +1 -1
- data/lib/sidekiq/job/iterable/active_record_enumerator.rb +1 -1
- data/lib/sidekiq/job/iterable.rb +1 -1
- data/lib/sidekiq/job.rb +55 -64
- data/lib/sidekiq/job_logger.rb +5 -0
- data/lib/sidekiq/job_retry.rb +6 -6
- data/lib/sidekiq/job_util.rb +7 -2
- data/lib/sidekiq/launcher.rb +1 -1
- data/lib/sidekiq/metrics/query.rb +6 -1
- data/lib/sidekiq/metrics/shared.rb +1 -1
- data/lib/sidekiq/paginator.rb +3 -0
- data/lib/sidekiq/processor.rb +7 -4
- data/lib/sidekiq/redis_client_adapter.rb +5 -3
- data/lib/sidekiq/redis_connection.rb +18 -9
- data/lib/sidekiq/tui/tabs/base_tab.rb +60 -15
- data/lib/sidekiq/tui/tabs/busy.rb +3 -17
- data/lib/sidekiq/tui/tabs/dead.rb +0 -5
- data/lib/sidekiq/tui/tabs/home.rb +12 -41
- data/lib/sidekiq/tui/tabs/metrics.rb +2 -19
- data/lib/sidekiq/tui/tabs/queues.rb +2 -14
- data/lib/sidekiq/tui/tabs/retries.rb +0 -5
- data/lib/sidekiq/tui/tabs/scheduled.rb +0 -5
- data/lib/sidekiq/tui/tabs/set_tab.rb +15 -20
- data/lib/sidekiq/tui.rb +59 -76
- data/lib/sidekiq/version.rb +1 -1
- data/lib/sidekiq/web/action.rb +2 -2
- data/lib/sidekiq/web/application.rb +5 -5
- data/lib/sidekiq/web/helpers.rb +24 -2
- data/lib/sidekiq/web.rb +2 -2
- data/sidekiq.gemspec +3 -2
- data/web/assets/javascripts/application.js +1 -0
- data/web/locales/da.yml +34 -0
- data/web/locales/de.yml +29 -1
- data/web/locales/en.yml +1 -0
- data/web/locales/es.yml +2 -0
- data/web/locales/fr.yml +11 -0
- data/web/locales/hi.yml +34 -0
- data/web/locales/it.yml +2 -0
- data/web/locales/ja.yml +19 -0
- data/web/locales/ko.yml +42 -0
- data/web/locales/nb.yml +32 -0
- data/web/locales/nl.yml +41 -0
- data/web/locales/pl.yml +50 -0
- data/web/locales/pt-BR.yml +13 -0
- data/web/locales/pt.yml +42 -0
- data/web/locales/ru.yml +26 -0
- data/web/locales/sv.yml +41 -0
- data/web/locales/ta.yml +81 -47
- data/web/locales/tr.yml +9 -0
- data/web/locales/uk.yml +9 -0
- data/web/locales/ur.yml +34 -4
- data/web/locales/zh-CN.yml +4 -0
- data/web/locales/zh-TW.yml +18 -0
- data/web/views/_footer.html.erb +1 -1
- data/web/views/_job_info.html.erb +7 -7
- data/web/views/_nav.html.erb +3 -9
- data/web/views/busy.html.erb +7 -6
- data/web/views/dead.html.erb +1 -1
- data/web/views/layout.html.erb +1 -1
- data/web/views/metrics.html.erb +1 -1
- data/web/views/metrics_for_job.html.erb +1 -1
- data/web/views/morgue.html.erb +3 -2
- data/web/views/profiles.html.erb +1 -1
- data/web/views/queues.html.erb +1 -0
- data/web/views/retries.html.erb +4 -3
- data/web/views/scheduled.html.erb +3 -2
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d57273306fa12b0b979c8bef039fd8457a7c09bdf2c66661e8e301be1300483
|
|
4
|
+
data.tar.gz: 45e32a880a7a5c2df9b885168775febdc8acc789c9ee321f2fff5f2295b0811d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2dde59200acb52993df285a82744a1da14e97cf70865333df817db73d8b76ae3c11dc83b36a9fe3a1cff7b0915fdb75721db060eb118300150d38341ea7057f1
|
|
7
|
+
data.tar.gz: de94f1d9b9be56f99ba8270ff121d70cf561c072ec0afdfc13b0ffd23f9c0fdb75295b8c6fe7243f6a1d425c18fa344c7737d9b7fef75e03c65cc48dee0f4019
|
data/Changes.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
[Sidekiq Changes](https://github.com/sidekiq/sidekiq/blob/main/Changes.md) | [Sidekiq Pro Changes](https://github.com/sidekiq/sidekiq/blob/main/Pro-Changes.md) | [Sidekiq Enterprise Changes](https://github.com/sidekiq/sidekiq/blob/main/Ent-Changes.md)
|
|
4
4
|
|
|
5
|
+
8.1.8
|
|
6
|
+
----------
|
|
7
|
+
|
|
8
|
+
- Define job class attributes once instead of a set of closures per job class, saving ~6KB of retained memory per job class
|
|
9
|
+
- Fix cancellation of iterable jobs before their first checkpoint [#7099]
|
|
10
|
+
- Do not count or log an interrupted iterable job as a failure [#7103]
|
|
11
|
+
- `config.redis=` now raises if the Redis connection pool was already created, instead of silently ignoring the new settings. The error names the code which created the pool. Apps which configure Sidekiq inside `Rails.application.reloader.to_prepare` should move that code out: `to_prepare` runs again on every code reload in development, and the second run will raise. `Sidekiq::CurrentAttributes.persist("Current")` takes a String, so it does not need `to_prepare` either [#7115]
|
|
12
|
+
- Refuse to start with a shutdown timeout (`-t`) below 3 seconds: a job pushed back at hard shutdown could be lost [#7129]
|
|
13
|
+
- Add missing strings for many non-English locales
|
|
14
|
+
- Misc bug fixes
|
|
15
|
+
- Migrate wiki to sidekiq.org/wiki
|
|
16
|
+
|
|
17
|
+
8.1.7
|
|
18
|
+
----------
|
|
19
|
+
|
|
20
|
+
- Forward compatibililty with Active Job 8.1 [#7019]
|
|
21
|
+
- Many minor fixes and test improvements [hammadxcm]
|
|
22
|
+
|
|
5
23
|
8.1.6
|
|
6
24
|
----------
|
|
7
25
|
|
data/README.md
CHANGED
|
@@ -3,6 +3,7 @@ Sidekiq
|
|
|
3
3
|
|
|
4
4
|
[](https://rubygems.org/gems/sidekiq)
|
|
5
5
|

|
|
6
|
+
[](https://www.rubyforum.org/tag/sidekiq)
|
|
6
7
|
|
|
7
8
|
Simple, efficient background jobs for Ruby.
|
|
8
9
|
|
|
@@ -31,7 +32,7 @@ Installation
|
|
|
31
32
|
Getting Started
|
|
32
33
|
-----------------
|
|
33
34
|
|
|
34
|
-
See the [Getting Started wiki page](https://
|
|
35
|
+
See the [Getting Started wiki page](https://sidekiq.org/wiki/Getting-Started) and follow the simple setup process.
|
|
35
36
|
You can watch [this YouTube playlist](https://www.youtube.com/playlist?list=PLjeHh2LSCFrWGT5uVjUuFKAcrcj5kSai1) to learn all about
|
|
36
37
|
Sidekiq and see its features in action. Here's the Web UI:
|
|
37
38
|
|
|
@@ -77,7 +78,7 @@ Problems?
|
|
|
77
78
|
**Do not directly email any Sidekiq committers with questions or problems.**
|
|
78
79
|
A community is best served when discussions are held in public.
|
|
79
80
|
|
|
80
|
-
If you have a problem, please review the [FAQ](https://
|
|
81
|
+
If you have a problem, please review the [FAQ](https://sidekiq.org/wiki/FAQ) and [Troubleshooting](https://sidekiq.org/wiki/Problems-and-Troubleshooting) wiki pages.
|
|
81
82
|
Searching the [issues](https://github.com/sidekiq/sidekiq/issues) for your problem is also a good idea.
|
|
82
83
|
|
|
83
84
|
Sidekiq Pro and Sidekiq Enterprise customers get private email support.
|
|
@@ -85,9 +86,10 @@ You can purchase at https://sidekiq.org; email support@contribsys.com for help.
|
|
|
85
86
|
|
|
86
87
|
Useful resources:
|
|
87
88
|
|
|
88
|
-
* Product documentation is in the [wiki](https://
|
|
89
|
+
* Product documentation is in the [wiki](https://sidekiq.org/wiki).
|
|
89
90
|
* Occasional announcements are made to the [@sidekiq](https://ruby.social/@sidekiq) Mastodon account.
|
|
90
91
|
* The [Sidekiq tag](https://stackoverflow.com/questions/tagged/sidekiq) on Stack Overflow has lots of useful Q & A.
|
|
92
|
+
* Join us in the `sidekiq` tag on the [Ruby Users Forum](https://www.rubyforum.org/tag/sidekiq).
|
|
91
93
|
|
|
92
94
|
Every Thursday morning is Sidekiq Office Hour: I video chat and answer questions.
|
|
93
95
|
See the [Sidekiq support page](https://sidekiq.org/support/) for details.
|
data/bin/sidekiqload
CHANGED
data/lib/sidekiq/api.rb
CHANGED
|
@@ -234,7 +234,7 @@ module Sidekiq
|
|
|
234
234
|
end
|
|
235
235
|
|
|
236
236
|
class History
|
|
237
|
-
def initialize(days_previous, start_date = nil
|
|
237
|
+
def initialize(days_previous, start_date = nil)
|
|
238
238
|
# we only store five years of data in Redis
|
|
239
239
|
raise ArgumentError if days_previous < 1 || days_previous > (5 * 365)
|
|
240
240
|
@days_previous = days_previous
|
|
@@ -627,6 +627,7 @@ module Sidekiq
|
|
|
627
627
|
Sidekiq.redis do |conn|
|
|
628
628
|
conn.zincrby(@parent.name, at.to_f - score, Sidekiq.dump_json(@item))
|
|
629
629
|
end
|
|
630
|
+
@score = at.to_f
|
|
630
631
|
end
|
|
631
632
|
|
|
632
633
|
# Enqueue this job from the scheduled or dead set so it will
|
|
@@ -856,15 +857,17 @@ module Sidekiq
|
|
|
856
857
|
}
|
|
857
858
|
|
|
858
859
|
msg = matched.first
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
860
|
+
begin
|
|
861
|
+
if msg
|
|
862
|
+
yield msg
|
|
863
|
+
@_size -= 1
|
|
864
|
+
end
|
|
865
|
+
ensure
|
|
866
|
+
# push the rest back onto the sorted set
|
|
867
|
+
conn.multi do |transaction|
|
|
868
|
+
nonmatched.each do |message|
|
|
869
|
+
transaction.zadd(name, score.to_f.to_s, message)
|
|
870
|
+
end
|
|
868
871
|
end
|
|
869
872
|
end
|
|
870
873
|
end
|
|
@@ -1357,7 +1360,7 @@ module Sidekiq
|
|
|
1357
1360
|
@records = Sidekiq.redis do |c|
|
|
1358
1361
|
# This throws away expired profiles
|
|
1359
1362
|
c.zremrangebyscore("profiles", "-inf", Time.now.to_f.to_s)
|
|
1360
|
-
#
|
|
1363
|
+
# retrieve records, newest to oldest
|
|
1361
1364
|
c.zrange("profiles", "+inf", 0, "byscore", "rev")
|
|
1362
1365
|
end
|
|
1363
1366
|
end
|
|
@@ -1415,7 +1418,7 @@ module Sidekiq
|
|
|
1415
1418
|
private
|
|
1416
1419
|
|
|
1417
1420
|
# Bulk-fetch iteration state for multiple JIDs in a single Redis pipeline.
|
|
1418
|
-
# Returns a Hash of { jid =>
|
|
1421
|
+
# Returns a Hash of { jid => State } for JIDs that have iteration state.
|
|
1419
1422
|
def bulk_fetch(jids)
|
|
1420
1423
|
raise ArgumentError unless jids
|
|
1421
1424
|
jids_to_fetch = Array(jids).compact.uniq
|
|
@@ -1452,7 +1455,7 @@ module Sidekiq
|
|
|
1452
1455
|
@cursor ||= begin
|
|
1453
1456
|
Sidekiq.load_json(raw["c"])
|
|
1454
1457
|
rescue JSON::ParserError
|
|
1455
|
-
|
|
1458
|
+
raw["c"]
|
|
1456
1459
|
end
|
|
1457
1460
|
end
|
|
1458
1461
|
|
data/lib/sidekiq/cli.rb
CHANGED
|
@@ -85,7 +85,7 @@ module Sidekiq # :nodoc:
|
|
|
85
85
|
|
|
86
86
|
WARNING: Your Redis instance will evict Sidekiq data under heavy load.
|
|
87
87
|
The 'noeviction' maxmemory policy is recommended (current policy: '#{maxmemory_policy}').
|
|
88
|
-
See: https://
|
|
88
|
+
See: https://sidekiq.org/wiki/Using-Redis#memory
|
|
89
89
|
|
|
90
90
|
EOM
|
|
91
91
|
end
|
|
@@ -144,7 +144,7 @@ module Sidekiq # :nodoc:
|
|
|
144
144
|
|
|
145
145
|
HOLIDAY_COLORS = {
|
|
146
146
|
# got other color-specific holidays from around the world?
|
|
147
|
-
# https://
|
|
147
|
+
# https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
|
|
148
148
|
"3-17" => "\e[1;32m", # St. Patrick's Day green
|
|
149
149
|
"10-31" => "\e[38;5;208m" # Halloween orange
|
|
150
150
|
}
|
|
@@ -336,6 +336,9 @@ module Sidekiq # :nodoc:
|
|
|
336
336
|
[:concurrency, :timeout].each do |opt|
|
|
337
337
|
raise ArgumentError, "#{opt}: #{@config[opt]} is not a valid value" if @config[opt].to_i <= 0
|
|
338
338
|
end
|
|
339
|
+
|
|
340
|
+
# timeout needs to be larger than BasicFetch::TIMEOUT + Manager::PAUSE_TIME
|
|
341
|
+
raise ArgumentError, "-t value too short, must be >= 3" if @config[:timeout].to_i < 3
|
|
339
342
|
end
|
|
340
343
|
|
|
341
344
|
def parse_options(argv)
|
data/lib/sidekiq/client.rb
CHANGED
|
@@ -142,9 +142,6 @@ module Sidekiq
|
|
|
142
142
|
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) })
|
|
143
143
|
raise ArgumentError, "Job 'at' Array must have same size as 'args' Array" if at.is_a?(Array) && at.size != args.size
|
|
144
144
|
|
|
145
|
-
# Use a smaller batch size by default for scheduled jobs since adding to sorted sets is more costly.
|
|
146
|
-
batch_size = items.delete(:batch_size) || items.delete("batch_size") || (at ? 100 : 1_000)
|
|
147
|
-
|
|
148
145
|
jid = items.delete("jid")
|
|
149
146
|
raise ArgumentError, "Explicitly passing 'jid' when pushing more than one job is not supported" if jid && args.size > 1
|
|
150
147
|
|
|
@@ -159,6 +156,9 @@ module Sidekiq
|
|
|
159
156
|
at = args.map { now + rand * spread_interval }
|
|
160
157
|
end
|
|
161
158
|
|
|
159
|
+
# Use a smaller batch size by default for scheduled jobs since adding to sorted sets is more costly.
|
|
160
|
+
batch_size = items.delete(:batch_size) || items.delete("batch_size") || (at ? 100 : 1_000)
|
|
161
|
+
|
|
162
162
|
normed = normalize_item(items)
|
|
163
163
|
slice_index = 0
|
|
164
164
|
result = args.each_slice(batch_size).flat_map do |slice|
|
data/lib/sidekiq/config.rb
CHANGED
|
@@ -65,6 +65,8 @@ module Sidekiq
|
|
|
65
65
|
@options[:error_handlers] << ERROR_HANDLER if @options[:error_handlers].empty?
|
|
66
66
|
@directory = {}
|
|
67
67
|
@redis_config = {}
|
|
68
|
+
@redis = nil
|
|
69
|
+
@redis_origin = nil
|
|
68
70
|
@capsules = {}
|
|
69
71
|
end
|
|
70
72
|
|
|
@@ -143,6 +145,18 @@ module Sidekiq
|
|
|
143
145
|
|
|
144
146
|
# All capsules must use the same Redis configuration
|
|
145
147
|
def redis=(hash)
|
|
148
|
+
if @redis
|
|
149
|
+
raise <<~MESSAGE
|
|
150
|
+
An attempt was made to configure Sidekiq Redis with `config.redis = ...` after the
|
|
151
|
+
connection pool was already created. This might come from another initializer,
|
|
152
|
+
or a background process started by a gem.
|
|
153
|
+
|
|
154
|
+
The pool was created from:
|
|
155
|
+
#{@redis_origin.join("\n ")}
|
|
156
|
+
|
|
157
|
+
MESSAGE
|
|
158
|
+
end
|
|
159
|
+
|
|
146
160
|
@redis_config = @redis_config.merge(hash)
|
|
147
161
|
end
|
|
148
162
|
|
|
@@ -157,7 +171,18 @@ module Sidekiq
|
|
|
157
171
|
def local_redis_pool
|
|
158
172
|
# this is our internal client/housekeeping pool. each capsule has its
|
|
159
173
|
# own pool for executing threads.
|
|
160
|
-
@redis
|
|
174
|
+
return @redis if @redis
|
|
175
|
+
|
|
176
|
+
@redis_origin = pool_origin
|
|
177
|
+
@redis = new_redis_pool(10, "internal")
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Remember which code created the pool, so a future error message can possibly reference it
|
|
181
|
+
def pool_origin
|
|
182
|
+
lib_dir = File.expand_path("..", __dir__)
|
|
183
|
+
frames = caller_locations(1, 30)
|
|
184
|
+
app = frames.reject { |loc| loc.path.start_with?(lib_dir) }
|
|
185
|
+
(app.empty? ? frames : app).first(5)
|
|
161
186
|
end
|
|
162
187
|
|
|
163
188
|
def new_redis_pool(size, name = "unset")
|
data/lib/sidekiq/embedded.rb
CHANGED
|
@@ -52,7 +52,7 @@ module Sidekiq
|
|
|
52
52
|
|
|
53
53
|
WARNING: Your Redis instance will evict Sidekiq data under heavy load.
|
|
54
54
|
The 'noeviction' maxmemory policy is recommended (current policy: '#{maxmemory_policy}').
|
|
55
|
-
See: https://
|
|
55
|
+
See: https://sidekiq.org/wiki/Using-Redis#memory
|
|
56
56
|
|
|
57
57
|
EOM
|
|
58
58
|
end
|
|
@@ -35,7 +35,7 @@ module Sidekiq
|
|
|
35
35
|
options[:of] ||= options.delete(:batch_size)
|
|
36
36
|
|
|
37
37
|
@relation.in_batches(**options, start: @cursor) do |relation|
|
|
38
|
-
first_record = relation.first
|
|
38
|
+
first_record = (options[:order] == :desc) ? relation.last : relation.first
|
|
39
39
|
yielder.yield(relation, first_record.id)
|
|
40
40
|
end
|
|
41
41
|
end
|
data/lib/sidekiq/job/iterable.rb
CHANGED
data/lib/sidekiq/job.rb
CHANGED
|
@@ -46,16 +46,48 @@ module Sidekiq
|
|
|
46
46
|
# The Options module is extracted so we can include it in ActiveJob::Base
|
|
47
47
|
# and allow native AJs to configure Sidekiq features/internals.
|
|
48
48
|
module Options
|
|
49
|
+
ATTRIBUTES = %i[sidekiq_options_hash sidekiq_retry_in_block sidekiq_retries_exhausted_block].freeze
|
|
50
|
+
|
|
49
51
|
def self.included(base)
|
|
50
52
|
base.extend(ClassMethods)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
base.
|
|
53
|
+
# Including this module (again) starts the class over with default
|
|
54
|
+
# options, even when a superclass has set some.
|
|
55
|
+
ATTRIBUTES.each { |name| base.instance_variable_set(:"@#{name}", nil) }
|
|
54
56
|
end
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
# The readers fall back to the superclass, so a subclass sees its
|
|
59
|
+
# parent's value until it sets its own.
|
|
60
|
+
def self.define_class_attribute(mod, name)
|
|
61
|
+
mod.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
62
|
+
def #{name}
|
|
63
|
+
if instance_variable_defined?(:@#{name})
|
|
64
|
+
@#{name}
|
|
65
|
+
elsif (parent = superclass).respond_to?(:#{name})
|
|
66
|
+
parent.#{name}
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def #{name}=(val)
|
|
71
|
+
@#{name} = val
|
|
72
|
+
end
|
|
73
|
+
RUBY
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def self.define_instance_attribute(mod, name)
|
|
77
|
+
mod.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
78
|
+
def #{name}
|
|
79
|
+
if instance_variable_defined?(:@#{name})
|
|
80
|
+
@#{name}
|
|
81
|
+
else
|
|
82
|
+
self.class.#{name}
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
attr_writer :#{name}
|
|
87
|
+
RUBY
|
|
88
|
+
end
|
|
58
89
|
|
|
90
|
+
module ClassMethods
|
|
59
91
|
##
|
|
60
92
|
# Allows customization for this type of Job.
|
|
61
93
|
# Legal options:
|
|
@@ -89,72 +121,31 @@ module Sidekiq
|
|
|
89
121
|
self.sidekiq_options_hash ||= Sidekiq.default_job_options
|
|
90
122
|
end
|
|
91
123
|
|
|
124
|
+
# Defines class-level attributes that subclasses inherit and can
|
|
125
|
+
# override, with instance-level readers and writers.
|
|
126
|
+
#
|
|
127
|
+
# Values are stored in instance variables on the class that set them,
|
|
128
|
+
# and readers fall back to the superclass. This defines each method
|
|
129
|
+
# once, on the class that declares the attribute, rather than a new
|
|
130
|
+
# closure every time a subclass sets a value.
|
|
92
131
|
def sidekiq_class_attribute(*attrs)
|
|
93
|
-
instance_reader = true
|
|
94
|
-
instance_writer = true
|
|
95
|
-
|
|
96
132
|
attrs.each do |name|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
undef_method(name) if method_defined?(name) || private_method_defined?(name)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
define_singleton_method(synchronized_getter) { nil }
|
|
104
|
-
singleton_class.class_eval do
|
|
105
|
-
private(synchronized_getter)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
define_singleton_method(name) { ACCESSOR_MUTEX.synchronize { send synchronized_getter } }
|
|
109
|
-
|
|
110
|
-
ivar = "@#{name}"
|
|
111
|
-
|
|
112
|
-
singleton_class.instance_eval do
|
|
113
|
-
m = "#{name}="
|
|
114
|
-
undef_method(m) if method_defined?(m) || private_method_defined?(m)
|
|
115
|
-
end
|
|
116
|
-
define_singleton_method(:"#{name}=") do |val|
|
|
117
|
-
singleton_class.class_eval do
|
|
118
|
-
ACCESSOR_MUTEX.synchronize do
|
|
119
|
-
undef_method(synchronized_getter) if method_defined?(synchronized_getter) || private_method_defined?(synchronized_getter)
|
|
120
|
-
define_method(synchronized_getter) { val }
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
if singleton_class?
|
|
125
|
-
class_eval do
|
|
126
|
-
undef_method(name) if method_defined?(name) || private_method_defined?(name)
|
|
127
|
-
define_method(name) do
|
|
128
|
-
if instance_variable_defined? ivar
|
|
129
|
-
instance_variable_get ivar
|
|
130
|
-
else
|
|
131
|
-
singleton_class.send name
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
val
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
if instance_reader
|
|
140
|
-
undef_method(name) if method_defined?(name) || private_method_defined?(name)
|
|
141
|
-
define_method(name) do
|
|
142
|
-
if instance_variable_defined?(ivar)
|
|
143
|
-
instance_variable_get ivar
|
|
144
|
-
else
|
|
145
|
-
self.class.public_send name
|
|
146
|
-
end
|
|
133
|
+
[singleton_class, self].each do |mod|
|
|
134
|
+
[name, :"#{name}="].each do |meth|
|
|
135
|
+
mod.undef_method(meth) if mod.method_defined?(meth) || mod.private_method_defined?(meth)
|
|
147
136
|
end
|
|
148
137
|
end
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
undef_method(m) if method_defined?(m) || private_method_defined?(m)
|
|
153
|
-
attr_writer name
|
|
154
|
-
end
|
|
138
|
+
Options.define_class_attribute(singleton_class, name)
|
|
139
|
+
Options.define_instance_attribute(self, name)
|
|
140
|
+
instance_variable_set(:"@#{name}", nil)
|
|
155
141
|
end
|
|
156
142
|
end
|
|
157
143
|
end
|
|
144
|
+
|
|
145
|
+
ATTRIBUTES.each do |name|
|
|
146
|
+
define_class_attribute(ClassMethods, name)
|
|
147
|
+
define_instance_attribute(self, name)
|
|
148
|
+
end
|
|
158
149
|
end
|
|
159
150
|
|
|
160
151
|
attr_accessor :jid
|
data/lib/sidekiq/job_logger.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "sidekiq/job_retry"
|
|
4
|
+
|
|
3
5
|
module Sidekiq
|
|
4
6
|
class JobLogger
|
|
5
7
|
def initialize(config)
|
|
@@ -16,6 +18,9 @@ module Sidekiq
|
|
|
16
18
|
|
|
17
19
|
Sidekiq::Context.add(:elapsed, elapsed(start))
|
|
18
20
|
@logger.info { "done" } unless @skip
|
|
21
|
+
rescue JobRetry::Skip
|
|
22
|
+
Sidekiq::Context.add(:elapsed, elapsed(start))
|
|
23
|
+
raise
|
|
19
24
|
rescue Exception
|
|
20
25
|
Sidekiq::Context.add(:elapsed, elapsed(start))
|
|
21
26
|
@logger.info { "fail" } unless @skip
|
data/lib/sidekiq/job_retry.rb
CHANGED
|
@@ -72,8 +72,8 @@ module Sidekiq
|
|
|
72
72
|
|
|
73
73
|
DEFAULT_MAX_RETRY_ATTEMPTS = 25
|
|
74
74
|
|
|
75
|
-
def initialize(
|
|
76
|
-
@config =
|
|
75
|
+
def initialize(cfg)
|
|
76
|
+
@config = cfg
|
|
77
77
|
@max_retries = Sidekiq.default_configuration[:max_retries] || DEFAULT_MAX_RETRY_ATTEMPTS
|
|
78
78
|
@backtrace_cleaner = Sidekiq.default_configuration[:backtrace_cleaner]
|
|
79
79
|
end
|
|
@@ -96,7 +96,7 @@ module Sidekiq
|
|
|
96
96
|
if msg["retry"]
|
|
97
97
|
process_retry(nil, msg, queue, e)
|
|
98
98
|
else
|
|
99
|
-
@
|
|
99
|
+
@config[:death_handlers].each do |handler|
|
|
100
100
|
handler.call(msg, e)
|
|
101
101
|
rescue => handler_ex
|
|
102
102
|
handle_exception(handler_ex, {context: "Error calling death handler", job: msg})
|
|
@@ -273,7 +273,7 @@ module Sidekiq
|
|
|
273
273
|
end
|
|
274
274
|
|
|
275
275
|
def run_death_handlers(job, exception)
|
|
276
|
-
@
|
|
276
|
+
@config[:death_handlers].each do |handler|
|
|
277
277
|
handler.call(job, exception)
|
|
278
278
|
rescue => e
|
|
279
279
|
handle_exception(e, {context: "Error calling death handler", job: job})
|
|
@@ -288,8 +288,8 @@ module Sidekiq
|
|
|
288
288
|
redis do |conn|
|
|
289
289
|
conn.multi do |xa|
|
|
290
290
|
xa.zadd("dead", now.to_s, payload)
|
|
291
|
-
xa.zremrangebyscore("dead", "-inf", now - @
|
|
292
|
-
xa.zremrangebyrank("dead", 0, - @
|
|
291
|
+
xa.zremrangebyscore("dead", "-inf", now - @config[:dead_timeout_in_seconds])
|
|
292
|
+
xa.zremrangebyrank("dead", 0, - @config[:dead_max_jobs])
|
|
293
293
|
end
|
|
294
294
|
end
|
|
295
295
|
end
|
data/lib/sidekiq/job_util.rb
CHANGED
|
@@ -27,7 +27,7 @@ module Sidekiq
|
|
|
27
27
|
if (unsafe_item = json_unsafe?(args))
|
|
28
28
|
msg = <<~EOM
|
|
29
29
|
Job arguments to #{job_class} must be native JSON types, but #{unsafe_item.inspect} is a #{unsafe_item.class}.
|
|
30
|
-
See https://
|
|
30
|
+
See https://sidekiq.org/wiki/Best-Practices
|
|
31
31
|
To disable this error, add `Sidekiq.strict_args!(false)` to your initializer.
|
|
32
32
|
EOM
|
|
33
33
|
|
|
@@ -79,7 +79,12 @@ module Sidekiq
|
|
|
79
79
|
|
|
80
80
|
RECURSIVE_JSON_UNSAFE = {
|
|
81
81
|
Integer => ->(val) {},
|
|
82
|
-
Float => ->(val) {
|
|
82
|
+
Float => ->(val) {
|
|
83
|
+
# JSON does not allow NaN / Infinity; reject them so strict_args!
|
|
84
|
+
# raises ArgumentError instead of a cryptic JSON::GeneratorError later.
|
|
85
|
+
return val unless val.finite?
|
|
86
|
+
nil
|
|
87
|
+
},
|
|
83
88
|
TrueClass => ->(val) {},
|
|
84
89
|
FalseClass => ->(val) {},
|
|
85
90
|
NilClass => ->(val) {},
|
data/lib/sidekiq/launcher.rb
CHANGED
|
@@ -235,7 +235,7 @@ module Sidekiq
|
|
|
235
235
|
MEMORY_GRABBER = case RUBY_PLATFORM
|
|
236
236
|
when /linux/
|
|
237
237
|
->(pid) {
|
|
238
|
-
IO.readlines("/proc/#{
|
|
238
|
+
IO.readlines("/proc/#{pid}/status").each do |line|
|
|
239
239
|
next unless line.start_with?("VmRSS:")
|
|
240
240
|
break line.split[1].to_i
|
|
241
241
|
end
|
|
@@ -169,7 +169,12 @@ module Sidekiq
|
|
|
169
169
|
|
|
170
170
|
def fetch_marks(time_range, granularity)
|
|
171
171
|
[].tap do |result|
|
|
172
|
-
|
|
172
|
+
days = (time_range.begin.utc.to_date..time_range.end.utc.to_date)
|
|
173
|
+
marks = @pool.with { |c|
|
|
174
|
+
c.pipelined { |pipeline|
|
|
175
|
+
days.each { |day| pipeline.hgetall("#{day.strftime("%Y%m%d")}-marks") }
|
|
176
|
+
}
|
|
177
|
+
}.flat_map(&:to_a)
|
|
173
178
|
|
|
174
179
|
marks.each do |timestamp, label|
|
|
175
180
|
time = Time.parse(timestamp)
|
|
@@ -21,7 +21,7 @@ module Sidekiq
|
|
|
21
21
|
# A precise time histogram stores every time. Instead we break times into a set of
|
|
22
22
|
# known buckets and increment counts of the associated time bucket. Even if we call
|
|
23
23
|
# the histogram a million times, we'll still only store 26 buckets.
|
|
24
|
-
# NB: needs to be thread-safe or
|
|
24
|
+
# NB: needs to be thread-safe or resilient to races.
|
|
25
25
|
#
|
|
26
26
|
# To store this data, we use Redis' BITFIELD command to store unsigned 16-bit counters
|
|
27
27
|
# per bucket per klass per minute. It's unlikely that most people will be executing more
|
data/lib/sidekiq/paginator.rb
CHANGED
|
@@ -60,6 +60,9 @@ module Sidekiq
|
|
|
60
60
|
|
|
61
61
|
def page_items(items, pageidx = 1, page_size = 25)
|
|
62
62
|
current_page = (pageidx.to_i < 1) ? 1 : pageidx.to_i
|
|
63
|
+
# A negative page_size makes Array#[] return nil instead of a slice, which
|
|
64
|
+
# would crash callers iterating the result (e.g. the Web UI Busy page).
|
|
65
|
+
page_size = 0 if page_size < 0
|
|
63
66
|
pageidx = current_page - 1
|
|
64
67
|
starting = pageidx * page_size
|
|
65
68
|
items = items.to_a
|
data/lib/sidekiq/processor.rb
CHANGED
|
@@ -30,15 +30,16 @@ module Sidekiq
|
|
|
30
30
|
attr_reader :capsule
|
|
31
31
|
|
|
32
32
|
def initialize(capsule, &block)
|
|
33
|
-
@config =
|
|
33
|
+
@config = capsule.config
|
|
34
|
+
@capsule = capsule
|
|
34
35
|
@callback = block
|
|
35
36
|
@down = false
|
|
36
37
|
@done = false
|
|
37
38
|
@job = nil
|
|
38
39
|
@thread = nil
|
|
39
40
|
@reloader = Sidekiq.default_configuration[:reloader]
|
|
40
|
-
@job_logger = (capsule.config[:job_logger] || Sidekiq::JobLogger).new(
|
|
41
|
-
@retrier = Sidekiq::JobRetry.new(capsule)
|
|
41
|
+
@job_logger = (capsule.config[:job_logger] || Sidekiq::JobLogger).new(@config)
|
|
42
|
+
@retrier = Sidekiq::JobRetry.new(@capsule)
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
def terminate(wait = false)
|
|
@@ -64,7 +65,7 @@ module Sidekiq
|
|
|
64
65
|
end
|
|
65
66
|
|
|
66
67
|
def start
|
|
67
|
-
@thread ||= safe_thread("#{
|
|
68
|
+
@thread ||= safe_thread("#{capsule.name}/processor", &method(:run))
|
|
68
69
|
end
|
|
69
70
|
|
|
70
71
|
private
|
|
@@ -286,6 +287,8 @@ module Sidekiq
|
|
|
286
287
|
|
|
287
288
|
begin
|
|
288
289
|
yield
|
|
290
|
+
rescue JobRetry::Skip
|
|
291
|
+
raise
|
|
289
292
|
rescue Exception
|
|
290
293
|
FAILURE.incr
|
|
291
294
|
raise
|
|
@@ -31,9 +31,11 @@ module Sidekiq
|
|
|
31
31
|
zremrangebyrank zremrangebyscore]
|
|
32
32
|
|
|
33
33
|
USED_COMMANDS.each do |name|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
|
35
|
+
def #{name}(*args, **kwargs)
|
|
36
|
+
@client.call("#{name}", *args, **kwargs)
|
|
37
|
+
end
|
|
38
|
+
RUBY
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
private
|