gpt4 book ai didi

ruby-on-rails - 将 ActiveJob 与 Sidekiq 一起使用与单独使用 Sidekiq 相比的优势

转载 作者:行者123 更新时间:2023-12-04 17:31:14 25 4
gpt4 key购买 nike

我正在在线阅读一些教程,这些教程告诉我们将 ActiveJob 与 Sidekiq 结合使用。但我不知道我们为什么要这样做。我看到 Sidekiq 具有 ActiveJob 的所有功能。

此外,在 Sidekiq 文档中:here

Warning: by doing job retry through ActiveJob, you lose a lot of Sidekiq functionality:

  1. Web UI visibility (the Retries tab will be empty)
  2. You cannot iterate through retries with the Sidekiq::RetrySet API.
  3. Sidekiq's log will not contain any failures or backtraces.
  4. Errors will not be reported to Sidekiq's global error handlers
  5. 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com