Home > Mobile >  Sidekiq's Delayed Extensions will be removed in Sidekiq 7.0
Sidekiq's Delayed Extensions will be removed in Sidekiq 7.0

Time:03-24

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.

CodePudding user response:

Rails now includes ActiveJob which allows you to schedule jobs in a more generic way. Background processing library such as sidekiq, delayed_job or resque can then hook into ActiveJob to actually execute the jobs you scheduled with ActiveJob.

Thus, you should move to use ActiveJob with your preferred background processing library.

CodePudding user response:

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)
  • Related