Sidekiq 的延迟扩展将在 Sidekiq 7.0 中删除

发布于 2025-01-16 13:50:08 字数 391 浏览 2 评论 0原文

我正在运行:

  • ruby​​ 3.1.1
  • Rails 7.0.2.3
  • Sidekiq 6.4.1

我正在从早期版本升级,并且我在initializers/sidekiq.rb 中有这行代码

Sidekiq::Extensions.enable_delay!

我收到一条警告消息:

config/initializers/sidekiq.rb:3:警告:Sidekiq 的延迟扩展将在 Sidekiq 7.0 中删除

但是我找不到该怎么做。如何替换 Delayed Extensions 提供的功能。我目前仅使用它来发送电子邮件。

I'm running:

  • ruby 3.1.1
  • Rails 7.0.2.3
  • Sidekiq 6.4.1

I was upgrading from earlier versions of the bunch and I have this line of code in initializers/sidekiq.rb

Sidekiq::Extensions.enable_delay!

I get a warning message saying

config/initializers/sidekiq.rb:3: warning: Sidekiq's Delayed Extensions will be removed in Sidekiq 7.0

However I couldn't find what to do. How to replace the functionality provided by Delayed Extensions. I'm currently using it just for emails.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜灵血窟げ 2025-01-23 13:50:08

从 Sidekiq 版本 5 开始,他们默认禁用延迟扩展,推理记录在此处 。由于它们的灵活性,它们很容易被误用。如果您使用延迟扩展只是为了将来运行作业,那么您可以使用两种替代品。

Sidekiq 处理此问题的方法称为 Scheduled Jobs,它看起来有点像 SomeSidekiqWorker.perform_in(3.hours, 'argument 1', 'argument 2'),或者如果您希望工作在特定时间进行执行,perform_at

此功能现在也内置于 ActiveJob 中(Rails 指南API 文档),看起来像SomeJob.set(wait: 3.hours).perform_later('参数 1', '参数 2')

标准 Rails 邮件程序的最简单选项类似于这些,它在底层使用 ActiveJob 机制 (API 文档)。

WelcomeMailer.welcome(User.first).deliver_later(wait: 3.hours)
WelcomeMailer.welcome(User.first).deliver_later(wait_until: 3.hours.from_now)

Starting in Sidekiq version 5, they disabled the delayed extensions by default, with their reasoning documented here. Due to their flexibility, they were prone to misuse.If all you were using the delayed extensions for was to run a job in the future, there are two replacements you can use.

Sidekiq's way to handle this is called Scheduled Jobs, which looks a bit like SomeSidekiqWorker.perform_in(3.hours, 'argument 1', 'argument 2'), or if you have a specific time you'd like the job to execute, perform_at.

This functionality is also now built into ActiveJob (Rails guide, API documentation), and looks like SomeJob.set(wait: 3.hours).perform_later('argument 1', 'argument 2').

The simplest option with a standard rails mailer would be something like these, which use the ActiveJob mechanism under the hood (API Documentation).

WelcomeMailer.welcome(User.first).deliver_later(wait: 3.hours)
WelcomeMailer.welcome(User.first).deliver_later(wait_until: 3.hours.from_now)
写给空气的情书 2025-01-23 13:50:08

他们正在转向第 3 方宝石。 https://github.com/mperham/sidekiq/issues/5076

They are moving to a 3rd party gem. https://github.com/mperham/sidekiq/issues/5076

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文