Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs about using string keys to create multiple limits per unit of time. #202

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,33 @@ IMPORTANT: Don't forget to specify `:key_suffix` and make it return different
values if you are using dynamic limit/period options. Otherwise, you risk
getting into some trouble.

[source,ruby]
----
class MyJob
include Sidekiq::Job
include Sidekiq::Throttled::Job

sidekiq_options queue: :my_queue

sidekiq_throttle(
concurrency: { limit: 10 },
# Allow 500 jobs per minute, 5,000 per hour, and 50,000 per day:
threshold: [
{ limit: 500, period: 1.minute, key_suffix: "minutely" },
{ limit: 5_000, period: 1.hour, key_suffix: "hourly" },
{ limit: 50_000, period: 1.day, key_suffix: "daily" },
]
)

def perform(project_id, user_id)
# ...
end
end
----

NOTE: `key_suffix` does not have to be a proc/lambda, it can just be a
string value. This can come in handy to set throttle limits for different
ranges of time

=== Concurrency throttling fine-tuning

Expand Down
Loading