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

Usage of sidekiq-unique-jobs with activejob #76

Closed
matthijsgroen opened this issue Mar 12, 2015 · 8 comments
Closed

Usage of sidekiq-unique-jobs with activejob #76

matthijsgroen opened this issue Mar 12, 2015 · 8 comments

Comments

@matthijsgroen
Copy link

To use the uniqueness with active job:

Sidekiq.default_worker_options = {
   'unique' => true,
   'unique_args' => proc do |args|
     [args.first.except('job_id')]
   end
}
SidekiqUniqueJobs.config.unique_args_enabled = true

Maybe you can update the readme for this?

@acegilz
Copy link

acegilz commented Mar 24, 2015

+1

@mhenrixon
Copy link
Owner

@IanVaughan
Copy link

The readme does not include the SidekiqUniqueJobs.config.unique_args_enabled = true, is this required too?

Also, where should this go?

@abacha
Copy link

abacha commented Mar 23, 2017

but if I dont want to use unique with all my workers?

@jolim
Copy link

jolim commented May 3, 2017

I've come up with a hack. It's flexible, so you can do what you want with this pattern.

With ActiveJob, it compares all jobs by their argument hash, so all jobs are subject to the action (drop/delay). In the configuration lambda, if you make a job unique by adding a uuid to the arguments hash, the job will not be subject to the action.

You can use any information in the jobs hash. The most interesting ones are the job_class and the queue_name. I've chosen to implement this hack with the latter by putting jobs onto a queue that I've named unique_jobs. You can create any queue name you want, or test if the [<class names>].include? r['job_class'] or whatever else makes you happy.

Sidekiq.default_worker_options = {
  unique: :until_executing,
  unique_args: lambda { |args|
    r = args.first.except('job_id')
    r[:make_unique] = SecureRandom.uuid unless r['queue_name'] == 'unique_jobs'
    [r]
  }
}

@mhenrixon
Copy link
Owner

I strongly recommend people to use sidekiq directly and not bother with active job. Why settle for a Fiat when you can drive a Ferrari?

@EPecherkin
Copy link

EPecherkin commented Jul 23, 2018

This comparison doesn't work here. It is all about a vendor-lock, which is always bad for a big business

@sharshenov
Copy link

Here is an implementation for ActiveJob: activejob-uniqueness

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

8 participants