ixti/sidekiq-throttled

Argument Error in dynamic Throttling

krishna-parajuli opened this issue · 4 comments

I have added

class MyWorker
  include Sidekiq::Worker
  include Sidekiq::Throttled::Worker

  sidekiq_options queue: 'my_queue', retry: 3

sidekiq_throttle concurrency: { limit: 10, key_suffix: ->(tx_id) { tx_id } }

  def perform(tx_id, *args)

to my worker

And it gives me Argument error as follows, I a using sidekiq-pro.

ArgumentError
--
wrong number of arguments (given 5, expected 1)
/app/workers/my_worker.rb:7:in block in
/home/user/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/sidekiq-throttled-0.11.0/lib/sidekiq/throttled/strategy/base.rb:15:in `
key'
/home/user/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/sidekiq-throttled-0.11.0/lib/sidekiq/throttled/strategy/concurrency.rb:71:in block in finalize!'
/home/user/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/sidekiq-5.2.5/lib/sidekiq.rb:97:in block in redis'
/home/user/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/connection_pool-2.2.2/lib/connection_pool.rb:65:in block (2 levels) in with'
/home/user/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `handle_interrupt'
/home/user/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/connection_pool-2.2.2/lib/connection_pool.rb:64:in `block in with'
/home/user/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `handle_interrupt'
/home/user/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in `with'
/home/user/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/sidekiq-5.2.5/lib/sidekiq.rb:94:in `redis'

Edit:
I have a lot(nearly 1k) of jobs enqueued and some jobs proceeds successfully, jobs that shows argument error are random at each run.

change:
sidekiq_throttle concurrency: { limit: 10, key_suffix: ->(tx_id) { tx_id } }
to:
sidekiq_throttle(concurrency: { limit: 10, key_suffix: ->(tx_id) { tx_id } })

@oozzal I made that change, and it is still showing the same error.

ixti commented

Your job accepts 1+ args. Key suffix proc shuold match that. So you should either use Proc:

sidekiq_throttle(concurrency: { limit: 10, key_suffix: proc { |tx_id| tx_id } })

Or be explicit in your Lambda signature:

sidekiq_throttle concurrency: { limit: 10, key_suffix: ->(tx_id, *) { tx_id } }

PS: I'd recommend being explicit in case of Proc too though :D

Thanks That solved. I'd send a PR to include this in example, so that it is easier to understand all the arguments pass in through key_suffix as well.