Reputation: 189
I am using Rails 4 in my app and this is how i create a new job:
class FetchJob < ActiveJob::Base
queue_as :fetchjob
def perform num
puts num
sleep 30
end
end
This code prints out the value of num
and then sleeps for 30 seconds. I am using sidekiq gem and redis to process this queue. I am queuing the jobs after a user is created.
class FecthJobController < ApplicationController
def create
@user = User.create(user_params)
FetchJob.perform_later(@user.id)
end
private
def user_params
....
end
end
Jobs in the queue are getting executed parallely. By jobs in the queue i mean like job1, job2, job3, job4 and so on. So how could i possibly execute these jobs sequentially. i.e only if job1 is completed, it'll process the job2 and then job3 and so on. How to lock it until the job is completed in sidekiq?
Upvotes: 2
Views: 3478
Reputation: 22238
You might find a hack that allows you to do what you want but let me suggest something else: you are using the wrong tool. Sidekiq is not designed to operate that way.
https://github.com/mperham/sidekiq/wiki/Best-Practices#3-embrace-concurrency
Upvotes: 1