sidekiq-throttled icon indicating copy to clipboard operation
sidekiq-throttled copied to clipboard

sidekiq_throttle_as doesn't work in inherited classes

Open RichardsonWTR opened this issue 2 years ago • 0 comments

What's the problem?

The throttle is not being used in inherited classes. I've just noticed this by looking at the sidekiq web interface and realized that there were more jobs running than the defined in the throttle. And the running jobs in the throttle stats were zero.

Version: 0.15.0

How to reproduce it?

Implement a worker base and an inherited one:

class BaseWorker
  include Sidekiq::Worker
  include Sidekiq::Throttled::Worker
  sidekiq_throttle_as :my_throttle
end

class ChildWorker < BaseWorker
end

Now use your worker and notice that the throttle will always be set to zero (no jobs in the throttle).
Another way of checking this behavior is to start more workers than the defined.

Where do I think that the problem is:

My guess is the problem lives inside the Registry#find_by_class that's used by Registry#get

Look at some discoveries that I've made in the Rails console:

> Sidekiq::Throttled::Registry.get(BaseWorker) # It returns an object

> Sidekiq::Throttled::Registry.get(ChildWorker) # It returns nil

RichardsonWTR avatar Jan 21 '22 11:01 RichardsonWTR