Per #3171, the delay extensions no longer work in Rails 5 development mode. They were originally added as a way for my employer, The Clymb, to migrate from delayed_job; now the need for a migration path is less important than it was three years ago. Deprecate the API in 4.3.0 and remove them in Sidekiq 5.0.
It is a bit sad delayed extension is going away.
I really like how it works and the new syntax of ActiveJob is not exact replacement (unless I'm missing something).
When we are using the delayed extension like UserMailer.delay.welcome(user.id) we are telling Sidekiq to execute the welcome method with some parameters. All the work of preparing the mailer object happens in Sidekiq and does not slow down web response time.
In contrast UserMailer.welcome(user.id).deliver_later is going to execute the welcome method immediately and send to Sidekiq the prepared mailer object.
It is true that the the mailer methods are not expected to do something complicated, but it is also true that we don't need them executed in the web request when they can be executed later, that was something I really love about Sidekiq and never tried to migrate to ActiveJob.
Is there no way to keep the current delayed extension behaviour? Is there an alternative that I'm missing different than deliver_later?
@kamen-hursev Mailer methods are not executed when deliver_later is invoked directly on the message. When we use UserMailer.welcome(user.id).deliver_later, only the mailer arguments are passed to ActiveJob. So this is the same behaviour as UserMailer.delay.welcome(user.id).
You can test this by running the following code:
message = UserMailer.welcome(user.id)
puts message
message.deliver_later
The above code will raise this error in Rails 5.
Thanks, @danishsatkut, you are absolutely right! I messed up big time while testing this before :disappointed:
@mperham why the move away from Delay Extension (I know it was originally a part of migration from DalyedJob)? I really liked the ability to write everything as a service object and then decide on the fly to run it through Sidekiq versus running it on the web server. In your experience, are there some limitations I'm maybe not thinking of? What I liked avoiding was having a bunch workers that simply wrap around a service (like CreateSellOrderService and then CreateSellOrderWorker that simple calls the service object.)
The plans aren't set in stone at all but likely the delay extensions will switch from opt-out to opt-in. You'll just need to do something like require 'sidekiq/delay' in your initializer to add the functionality back. I don't like it personally because it pulls in YAML, serializes the entire object state and adds three methods to Class but it is useful and popular so we can't just drop it.
The delay extensions should be working again on master now and in the upcoming 4.2.7 release.
thanks @mperham!