【发布时间】:2020-11-03 13:43:47
【问题描述】:
我有两个队列:development 和 ar_updater。我有一堆 sidekiq 工作人员不断更新 ActiveRecord 对象,但有时他们同时查询记录,而不是仅在另一个人更新它之后。因此,我正在考虑只创建一个队列并将其并发限制为 1,以便可以附加正确的数据。
这是我的config/sidekiq.yml 文件:
development:
:concurrency: 10
ar_updater:
:concurrency: 1
:queues:
- development
- ar_updater
然后我只有一个简单的工人,看起来像这样:
class ArUpdateWorker
include Sidekiq::Worker
sidekiq_options queue: "ar_updater"
def perform(options)
options = options.transform_keys(&:to_sym)
schedule_id = options[:schedule_id]
progress = options[:progress]
schedule = Schedule.find(schedule_id)
old_progress = schedule.current_progress
schedule.update(current_progress: old_progress + progress)
end
end
有没有办法确保这些工作人员在这个特定队列中一次只运行一个?当多次调用ArUpdateWorker 时,sidekiq 似乎忽略了并发性,只是根据需要运行 worker,但是如果我将 worker 的队列切换到 development,那么它会遵守 10 的并发性。有点混乱。
似乎解决此问题的唯一方法是使用在命令行界面上设置的并发设置运行 sidekiq
【问题讨论】:
标签: ruby-on-rails sidekiq