Skip to content

Its possible to use this gem like this ?  #199

Description

@brunomiguelpinto

i wanted to have a shared rule per job but have a limit of something per key ( per organization )

Sidekiq::Throttled::Registry.add(
  :shared_throttling_rule,
  concurrency: [
    { limit: 10, key_suffix: ->(args) { args['org_id'] || 'default' } }
  ]
)

and then I wanted different jobs to share the same limit per organization

class TesteOneJob < ApplicationJob
  include Sidekiq::Throttled::Worker
  sidekiq_throttle_as :shared_throttling_rule

  def perform(job_number, org_id:)
    Rails.logger.debug "Performing TesteOneJob #{job_number} for organization #{org_id} at #{Time.zone.now}"
    sleep(1)
    Rails.logger.debug "Finished TesteOneJob #{job_number} at #{Time.zone.now}"
  end
end

class TesteJob < ApplicationJob
  include Sidekiq::Throttled::Worker
  sidekiq_throttle_as :shared_throttling_rule

  def perform(job_number, org_id:)
    Rails.logger.debug "Performing TesteJob #{job_number} for organization #{org_id} at #{Time.zone.now}"
    sleep(1)
    Rails.logger.debug "Finished TesteJob #{job_number} at #{Time.zone.now}"
  end
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions