Delayed_Job - handle manually with ActionMailer?

So, I am using Delayed Jobs, and I am trying to figure out how to make all my mail programs linger. Right now, I put handle_asynchronously on all of my mailing list methods ... but I don't think this will work.

 def first_notification(time) @time = time mail :to => time.person.email, :from => " email@example.com ", :subject => "#{time.person.name} wants to say hi" end handle_asynchronously :advisor_first_notification, :priority => 20 

I don't think this will work, because I call it the following:

 UserMailer.first_notification(@time).deliver 

So how would he handle the .deliver part of this? I am getting an exception now.

 EXCEPTION: #<ArgumentError: wrong number of arguments (1 for 0)> 

Because of this, I feel that something is messed up in the delivery aspect.

I would prefer not to have a separate task file for each letter (since I have a lot of them), so is this the right way to handle this?

The only other possibility I can think of is to encapsulate calls to a method in my models and have them handle_asynchronously - so they can call the whole thing right away.

+6
source share
3 answers

The handle_asynchronously is a bit complicated ... Instead of the handle_asynchronously syntax:

 UserMailer.delay.first_notification(@time) 

The "trick" has delay() before the mailer method

+10
source

In addition to Jesse's answer, collectidea fork delayed_job indicates that you should definitely not use the delivery method at all with the Rails 3 Mailer code:

 # without delayed_job Notifier.signup(@user).deliver # with delayed_job Notifier.delay.signup(@user) 
+4
source

I started working by doing the following:

 class MyMailer < ActionMailer::Base def send_my_mail_method(*args) MyMailer.my_mail_method(*args).deliver end handle_asynchronously :send_my_mail_method def my_mail_method(*args) # mail call ... end end 

I like this method because it allows me to verify that delivery is happening interactively, without having to do something stupid, like mocking a delay call.

0
source

Source: https://habr.com/ru/post/888738/


All Articles