delayed_job icon indicating copy to clipboard operation
delayed_job copied to clipboard

Deliver_later no longer working after Rails upgrade

Open kellenberger opened this issue 5 years ago • 5 comments

We upgraded our Rails application from version 5.0 to version 6.0. Somewhere along the process deliver_later for our Mailers stopped working. I get the following error message:

> TestMailer.standard_template_test_mail.deliver_later
Enqueued ActionMailer::MailDeliveryJob (Job ID: 30f33ee7-2464-4922-a8cd-414c374fd0f7) to DelayedJob(mailers) with arguments: "TestMailer", "standard_template_test_mail", "deliver_now", {:args=>[]}
Traceback (most recent call last):
        1: from (irb):3
NoMethodError (undefined method `id' for {:args=>[]}:Hash)

For some reason it wants to call a method id on the arguments hash. Additionally I have found out that it works if I use the approach specified in the README for Rails version 3:

> TestMailer.delay.standard_template_test_mail
(0.4ms)  BEGIN
Delayed::Backend::ActiveRecord::Job Create (0.7ms)  INSERT INTO `delayed_jobs` (`handler`, `run_at`, `queue`, `created_at`, `updated_at`) VALUES ('--- !ruby/object:Delayed::PerformableMailer\nobject: !ruby/class \'TestMailer\'\nmethod_name: :standard_template_test_mail\nargs: []\n', '2019-11-19 09:35:49', 'default', '2019-11-19 09:35:49', '2019-11-19 09:35:49')
(24.7ms)  COMMIT
=> #<Delayed::Backend::ActiveRecord::Job id: 2, priority: 0, attempts: 0, handler: "--- !ruby/object:Delayed::PerformableMailer\nobject...", last_error: nil, run_at: "2019-11-19 09:35:49", locked_at: nil, failed_at: nil, locked_by: nil, queue: "default", created_at: "2019-11-19 09:35:49", updated_at: "2019-11-19 09:35:49">

I have also tried reinstalling the Gems to no effect. Reading from the Gemfile.lock I get the following versions for the gems:

rails (6.0.0)
delayed_job (4.1.8)
delayed_job_active_record (4.1.4)
daemons (1.3.1)

Does anybody know what could cause this?

kellenberger avatar Nov 19 '19 12:11 kellenberger

@skell94 - Did you find the solution?

ACPK avatar Jul 02 '20 15:07 ACPK

@ACPK No, I just used the Rails 3 syntax.

TestMailer.delay.standard_template_test_mail

kellenberger avatar Jul 02 '20 15:07 kellenberger

Something else is interfering here. Stock rails and DJ do not have an issue. Rails 6 started heavily migrating to using ruby keyword arguments and I suspect something else either in other gems or your codebase isn't playing quite right with the new arguments. Check any job callbacks you implemented in your codebase and any other gems that attempt to hook into actionmailer or activejob. It could also be something messing with log subscribers. I suspect a complete stack trace and not a basic irb error message would be much more illuminating.

albus522 avatar Dec 09 '20 20:12 albus522

If you are using mailer parameters, you need to call .with method must be called before the .delay method like so:

Notifier.with(foo: 1, bar: 2).delay.signup(@user)

Does this help?

johnnyshields avatar Apr 05 '21 05:04 johnnyshields

You will also have your tests broken, for that you can check out this solution https://stackoverflow.com/questions/57776074/rails-6-deliver-later-doesnt-affect-actionmailerbase-deliveries/75056934#75056934

aleonjob avatar Jan 09 '23 14:01 aleonjob

Closing stale

albus522 avatar Jul 26 '24 19:07 albus522