I could have 3 jobs pending in the queue, as soon as the first Job is done, all remaining workers get executed at the same time. Why is that? I want each worker to get a lock and make the other jobs wait, in a serialized-fashion.
class StuffWorker
include Sidekiq::Worker
sidekiq_options lock: :until_executed,
lock_timeout: 999,
lock_info: true,
lock_args_method: :lock_args
def self.lock_args(args)
[args[0], args[1]]
end
def perform(company_id, person_id)
sleep 10
logger.info "STARTING IT! at #{DateTime.now.strftime('%H:%M:%S')}"
end
end
Produces the following:
JID-ce8c692b5341adb7a24584ab INFO: STARTING IT! at 23:29:52
JID-ce8c692b5341adb7a24584ab INFO: done: 10.728 sec
JID-ca8dac1cbd7cbaf5d87f6096 INFO: STARTING IT! at 23:30:02
JID-463bfe792775e1412d3c0af7 INFO: STARTING IT! at 23:30:02
JID-463bfe792775e1412d3c0af7 INFO: done: 17.754 sec
JID-ca8dac1cbd7cbaf5d87f6096 INFO: done: 14.024 sec
Possible, what you want is a runtime lock only, not queue lock. You have to use while_executing
lock type https://github.com/mhenrixon/sidekiq-unique-jobs#while-executing .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.