ixti/sidekiq-throttled

sidekiq_throttle_as doesn't work in inherited classes

RichardsonWTR opened this issue · 1 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
ixti commented

For now you can fix this with:

Sidekiq::Throttled.configuration.inherit_strategies = true

I will make this default behaviour in the future. But I need to find a solution that will be least confusing. As there are too many edge cases.