我正在在线阅读一些教程,这些教程告诉我们将 ActiveJob 与 Sidekiq 结合使用。但我不知道我们为什么要这样做。我看到 Sidekiq 具有 ActiveJob 的所有功能。
此外,在 Sidekiq 文档中:here
Warning: by doing job retry through ActiveJob, you lose a lot of Sidekiq functionality:
- Web UI visibility (the Retries tab will be empty)
- You cannot iterate through retries with the Sidekiq::RetrySet API.
- Sidekiq's log will not contain any failures or backtraces.
- Errors will not be reported to Sidekiq's global error handlers
- Many advanced Sidekiq features (e.g. Batches) will not work with AJ retries.
这是一个信号,让我觉得我们不应该将 Sidekiq 与 ActiveJob 一起使用。我对 ActiveJob 的理解有误吗?将 ActiveJobs 与 sidekiq 一起使用有什么优势吗?
谢谢
最佳答案
对我来说,ActiveJob 的主要特点是对 GlobalId 的支持。比较:
Sidekiq :
class SomeJob
include Sidekiq::Worker
def perform(record_id)
record = Record.find(record_id)
record.do_something
end
end
SomeJob.perform_async(record.id)
活跃工作 :
class SomeJob < ApplicationJob
def perform(record)
record.do_something
end
end
SomeJob.perform_later(record)
如此方便,更清洁! 😍
关于重试——是的,这是个问题,而且我不知道为什么 ActiveJob 中忽略了为底层系统配置每个作业的参数的功能。就解决方法而言,可以使用 gem activejob-retry :
class SomeJob
include ActiveJob::Retry.new(strategy: :exponential, limit: 0)
end
这将禁用 ActiveJob 的重试,而 Sidekiq 的重试仍然有效。可以通过
Sidekiq.default_worker_options['retry'] = 2
在配置文件中配置 sidekiq 的重试次数更新
重试问题已在 Sidekiq 6.0 中修复🎉
关于ruby-on-rails - 将 ActiveJob 与 Sidekiq 一起使用与单独使用 Sidekiq 相比的优势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45305175/