ixti / sidekiq-throttled

Concurrency and rate-limit throttling for Sidekiq
MIT License
698 stars 75 forks source link

Add a concurrency per user, but also total concurrency as a whole #190

Closed princejoseph closed 2 months ago

princejoseph commented 2 months ago

This is a question more, but cant apply the label

Trying to do maximum 1 job per user concurrently but also maximum of 10 jobs concurrently

sidekiq_throttle(
    # Allow maximum 10 concurrent jobs per project at a time and maximum 1 job per user
    concurrency: [
      { limit: 1, key_suffix: -> (user_id) { user_id } },
      { limit: 10 }
    ]
mnovelo commented 2 months ago

Are you asking whether that's correct? I think it'll work fine if you're ok with your suffix essentially being ":#{*user_id}" which for user_id = 1 would be :[1] according to this line

princejoseph commented 2 months ago

according to this line

yes, was more thinking if the functionality works for both scenarios (like 1 job per user but max total 10 irrespective of the user). I tested it manually and it does work

mnovelo commented 2 months ago

We've done something similar successfully in production

princejoseph commented 2 months ago

Closing this as it does work when I tested it. Thank you @mnovelo