sidekiq-throttled 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +27 -0
- data/lib/sidekiq/throttled/strategy.rb +13 -6
- data/lib/sidekiq/throttled/strategy_collection.rb +1 -1
- data/lib/sidekiq/throttled/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07f60ab84ab53725f6189d8a142ccb7d5596ea408a5d52087e2665420c92a276
|
4
|
+
data.tar.gz: 489d3d9a5a72dc20af8295d6942d4abdc9a27dfffdf917b753a08af78184d59e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bac5ad071e0de8913f80f8c78cec87ee98c61da77a48c46000ba3680f0eeb684b2970c69d256b61cf5d1b680121f2762a0ae3c9220729ee25140ba6cbf3f9598
|
7
|
+
data.tar.gz: 92d08e2c0f76716816385b24df2c06092fa416ceb22714657967e2e312fe04357000db45fc18ee4f99d5eab57b6c267d93556a8064cb704478590b457ec48f2f
|
data/README.adoc
CHANGED
@@ -262,6 +262,33 @@ IMPORTANT: Don't forget to specify `:key_suffix` and make it return different
|
|
262
262
|
values if you are using dynamic limit/period options. Otherwise, you risk
|
263
263
|
getting into some trouble.
|
264
264
|
|
265
|
+
[source,ruby]
|
266
|
+
----
|
267
|
+
class MyJob
|
268
|
+
include Sidekiq::Job
|
269
|
+
include Sidekiq::Throttled::Job
|
270
|
+
|
271
|
+
sidekiq_options queue: :my_queue
|
272
|
+
|
273
|
+
sidekiq_throttle(
|
274
|
+
concurrency: { limit: 10 },
|
275
|
+
# Allow 500 jobs per minute, 5,000 per hour, and 50,000 per day:
|
276
|
+
threshold: [
|
277
|
+
{ limit: 500, period: 1.minute, key_suffix: "minutely" },
|
278
|
+
{ limit: 5_000, period: 1.hour, key_suffix: "hourly" },
|
279
|
+
{ limit: 50_000, period: 1.day, key_suffix: "daily" },
|
280
|
+
]
|
281
|
+
)
|
282
|
+
|
283
|
+
def perform(project_id, user_id)
|
284
|
+
# ...
|
285
|
+
end
|
286
|
+
end
|
287
|
+
----
|
288
|
+
|
289
|
+
NOTE: `key_suffix` does not have to be a proc/lambda, it can just be a
|
290
|
+
string value. This can come in handy to set throttle limits for different
|
291
|
+
ranges of time
|
265
292
|
|
266
293
|
=== Concurrency throttling fine-tuning
|
267
294
|
|
@@ -143,24 +143,27 @@ module Sidekiq
|
|
143
143
|
when NilClass
|
144
144
|
work.queue
|
145
145
|
when String, Symbol
|
146
|
-
requeue_to
|
146
|
+
requeue_to
|
147
147
|
else
|
148
148
|
raise ArgumentError, "Invalid argument for `to`"
|
149
149
|
end
|
150
150
|
|
151
151
|
target = work.queue if target.nil? || target.empty?
|
152
152
|
|
153
|
-
target.
|
153
|
+
target.to_s
|
154
154
|
end
|
155
155
|
|
156
156
|
# Push the job back to the head of the queue.
|
157
|
+
# The queue name is expected to include the "queue:" prefix, so we add it if it's missing.
|
157
158
|
def re_enqueue_throttled(work, target_queue)
|
159
|
+
target_queue = "queue:#{target_queue}" unless target_queue.start_with?("queue:")
|
160
|
+
|
158
161
|
case work.class.name
|
159
162
|
when "Sidekiq::Pro::SuperFetch::UnitOfWork"
|
160
163
|
# Calls SuperFetch UnitOfWork's requeue to remove the job from the
|
161
164
|
# temporary queue and push job back to the head of the target queue, so that
|
162
165
|
# the job won't be tried immediately after it was requeued (in most cases).
|
163
|
-
work.queue = target_queue
|
166
|
+
work.queue = target_queue
|
164
167
|
work.requeue
|
165
168
|
else
|
166
169
|
# This is the same operation Sidekiq performs upon `Sidekiq::Worker.perform_async` call.
|
@@ -168,10 +171,13 @@ module Sidekiq
|
|
168
171
|
end
|
169
172
|
end
|
170
173
|
|
174
|
+
# Reschedule the job to be executed later in the target queue.
|
175
|
+
# The queue name should NOT include the "queue:" prefix, so we remove it if it's present.
|
171
176
|
def reschedule_throttled(work, target_queue)
|
172
|
-
|
173
|
-
|
174
|
-
|
177
|
+
target_queue = target_queue.delete_prefix("queue:")
|
178
|
+
message = JSON.parse(work.job)
|
179
|
+
job_class = message.fetch("wrapped") { message.fetch("class") { return false } }
|
180
|
+
job_args = message["args"]
|
175
181
|
|
176
182
|
# Re-enqueue the job to the target queue at another time as a NEW unit of work
|
177
183
|
# AND THEN mark this work as done, so SuperFetch doesn't think this instance is orphaned
|
@@ -179,6 +185,7 @@ module Sidekiq
|
|
179
185
|
# but your job should be idempotent anyway, right?
|
180
186
|
# The job running twice was already a risk with SuperFetch anyway and this doesn't really increase that risk.
|
181
187
|
Sidekiq::Client.enqueue_to_in(target_queue, retry_in(work), Object.const_get(job_class), *job_args)
|
188
|
+
|
182
189
|
work.acknowledge
|
183
190
|
end
|
184
191
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-throttled
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Zapparov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -90,9 +90,9 @@ licenses:
|
|
90
90
|
- MIT
|
91
91
|
metadata:
|
92
92
|
homepage_uri: https://github.com/ixti/sidekiq-throttled
|
93
|
-
source_code_uri: https://github.com/ixti/sidekiq-throttled/tree/v1.5.
|
93
|
+
source_code_uri: https://github.com/ixti/sidekiq-throttled/tree/v1.5.2
|
94
94
|
bug_tracker_uri: https://github.com/ixti/sidekiq-throttled/issues
|
95
|
-
changelog_uri: https://github.com/ixti/sidekiq-throttled/blob/v1.5.
|
95
|
+
changelog_uri: https://github.com/ixti/sidekiq-throttled/blob/v1.5.2/CHANGES.md
|
96
96
|
rubygems_mfa_required: 'true'
|
97
97
|
post_install_message:
|
98
98
|
rdoc_options: []
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
rubygems_version: 3.
|
112
|
+
rubygems_version: 3.5.22
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Concurrency and rate-limit throttling for Sidekiq
|