key-suffix ussage
danielgomezrico opened this issue · 3 comments
Hi
What do you mean by some trouble?
NB 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.
I want to speficy a static key-suffix for multiple jobs, so I can throttle all of them togetter with the same setup using the same key.
Is that possible?
I tried putting a static key-suffix but that results in never throttling any job.
I undestood badly the readme, it turns out that the key should receive a function that receive the same number of parameters as the perform
function of the worker:
ex:
class MyWorker
include Sidekiq::Worker
include Sidekiq::Throttled::Worker
sidekiq_options queue: "my_queue"
sidekiq_throttle({
:threshold => {
:limit => 100,
:period => 10.second,
:key_suffix => -> (_, _) { "my-key" }
}
})
def perform(call, email)
end
end
Otherwise the throttle does not work and each job run as fast as it can.
Mm, yes. You can pass Proc instead of Lambda so that it won't require to have same amount of args. These are different way of achieving that:
# Proc
proc { "my-key" }
proc { |*| "my-key" }
# Lambda
lambda { |*| "my-key" }
->(*) { "my-key" }
@ixti yeah it worked, thanks