App crashing with sidekiq-throttled and Ruby 3.0.1
popcorn opened this issue · 1 comments
popcorn commented
I'm upgrading Ruby to 3.0.1 and sidekiq-throttle
fails with the following error:
/app/vendor/bundle/ruby/3.0.0/gems/sidekiq-throttled-0.13.0/lib/sidekiq/throttled/worker.rb:76:in `sidekiq_throttle': wrong number of arguments (given 1, expected 0) (ArgumentError)
It is the same error I would get when not using a different number of arguments for key_suffix
and perform
.
This is the worker class and it works with Ruby 2.5 (code is redacted for brevity's sake)
class SyncSubscriber
include Sidekiq::Worker
include Sidekiq::Throttled::Worker
sidekiq_options queue: 'priority'
sidekiq_throttle({
threshold: {
limit: 5,
period: 1.second,
key_suffix: ->(sub_id) { sub_id }
}
})
def perform(sub_id)
# Do the sync
end
end
Anyone had this problem?
ixti commented
TLDR; You should not wrap throttle config in {}
:
class SyncSubscriber
include Sidekiq::Worker
include Sidekiq::Throttled::Worker
sidekiq_options queue: 'priority'
sidekiq_throttle threshold: {
limit: 5,
period: 1.second,
key_suffix: ->(sub_id) { sub_id }
}
def perform(sub_id)
# Do the sync
end
end
Need to update README.
As of Ruby 3.x.x foo({ abc: 123 })
is sending :foo
message with given Hash as a single argument and does not tries to map given Hash to keyword arguments:
def foo(x: 123); end
foo({ x: 123 }) # will fail in Ruby 3.0.0+
# In Ruby 3.0.0+ you should do:
foo(x: 123)