Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique args being considered? #137

Closed
andresakata opened this issue Oct 21, 2015 · 1 comment
Closed

Unique args being considered? #137

andresakata opened this issue Oct 21, 2015 · 1 comment

Comments

@andresakata
Copy link
Contributor

I created an worker like that:

class SomeWorker
  include Sidekiq::Worker
  sidekiq_options unique: :while_executing, unique_args: :filtered_args

  def self.filtered_args(some_id)
    [some_id]
  end

  def perform(some_id)
    puts 'Running ' + some_id.to_s
    sleep(5)
  end
end

Then, i expected the following behavior:

SomeWorker.perform_async(1) < worker starts immediately
SomeWorker.perform_async(2) < worker starts immediately in a different thread
SomeWorker.perform_async(1) < worker waits while first call is in execution

But, what really happens:

SomeWorker.perform_async(1) < worker starts immediately
SomeWorker.perform_async(2) < worker starts after first call ends
SomeWorker.perform_async(1) < worker starts after second call ends

Am i doing something wrong?

@mhenrixon
Copy link
Owner

WhileExecuting will be unique like the name suggests while executing. To begin with.... In your example you have no need for the filtered_args method since the arguments passed to perform will be used for uniqueness if no unique args method or proc is specified. The uniqueness won't stop a job from being started it will just pause there until the lock can be acquired so your assumption of what really happens is wrong. All of the jobs will be passed successfully to the middleware and wait there while trying to acquire the runtime lock/mutex/semaphore or whatever other name you can thing of. As you might have noticed the other locks prevents jobs from being scheduled to a queue and while_executing will allow any number of jobs to be scheduled but only one of those to run at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants