Class: Sidekiq::FairTenant::ClientMiddleware
- Inherits:
-
Object
- Object
- Sidekiq::FairTenant::ClientMiddleware
- Defined in:
- lib/sidekiq/fair_tenant/client_middleware.rb
Overview
Client middleware re-routing jobs of overly active tenants to slower queues based on thresholds
Instance Method Summary collapse
-
#call(worker, job, queue, redis_pool) ⇒ Object
Re-routes job to the most appropriate queue, based on tenant’s throttling rules rubocop:disable Metrics/MethodLength.
Instance Method Details
#call(worker, job, queue, redis_pool) ⇒ Object
Re-routes job to the most appropriate queue, based on tenant’s throttling rules rubocop:disable Metrics/MethodLength
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sidekiq/fair_tenant/client_middleware.rb', line 9 def call(worker, job, queue, redis_pool) job_class = job_class(worker, job) arguments = job["wrapped"] ? job.dig("args", 0, "arguments") : job["args"] return yield unless enabled?(job_class, job, queue) job["fair_tenant"] ||= tenant_id(job_class, job, arguments) unless job["fair_tenant"] logger.warn "#{job_class} with args #{arguments.inspect} won't be throttled: missing `fair_tenant` in job" return yield end redis_pool.then do |redis| register_job(job_class, job, queue, redis) job["queue"] = assign_queue(job_class, job, queue, redis) end yield end |