我正在使用delayed_job 来处理后台作业。我最近遇到了 devse_async gem 来集成delayed_job 和设计。
当delayed_job 处理队列中的电子邮件作业时,我收到错误数量的参数(1 对2)错误。我应该注意我正在使用 Mandrill 的 API 来发送这些电子邮件。
延迟作业控制台
Starting job worker
[Worker(host:MacBook-Pro.local pid:21007)] Job Devise::Async::Backend::DelayedJob#perform (id=1) RUNNING
[Worker(host:MacBook-Pro.local pid:21007)] Job Devise::Async::Backend::DelayedJob#perform (id=1) FAILED (0 prior attempts) with ArgumentError: wrong number of arguments (1 for 2)
[Worker(host:MacBook-Pro.local pid:21007)] 1 jobs processed at 30.3564 j/s, 1 failed
痕迹
wrong number of arguments (1 for 2)
/Users/Sites/app/mailers/devise_mailer.rb:6:in `confirmation_instructions'
设计邮件程序
class DeviseMailer < MandrillMailer::TemplateMailer
include Devise::Controllers::UrlHelpers
include Devise::Mailers::Helpers
default from: 'no-reply@foobar.com'
def confirmation_instructions(record, token)
@resource = record
# Route mailer to send the proper subject and template
if @resource.pending_reconfirmation?
confirmation_template = 'Reconfirmation Instructions'
confirmation_subject = 'Confirm your new email'
else
confirmation_template = 'Confirmation Instructions'
confirmation_subject = 'Confirmation Email'
end
# Include proper greeting in email based on User type
recipient_name = nil
if @resource.type == "Business"
recipient_name = record.business_name
else
recipient_name = record.first_name
end
puts "sending confirmation email"
host = ActionMailer::Base.default_url_options[:host]
mandrill_mail template: confirmation_template,
subject: confirmation_subject,
from_name: 'foobar',
to: { email: 'contact@foobar.ca' },
vars: {
'FNAME' => recipient_name,
'LIST_COMPANY' => "foobar",
'HTML_LIST_ADDRESS_HTML' => "foobar",
'CONFIRMATION_LINK' => "%s/users/confirmation?confirmation_token=#{record.confirmation_token}" % ENV['MAIL_HOST']
# "http://0.0.0.0:3000/users/confirmation?confirmation_token=#{record.confirmation_token}"
},
async: true
end
end
注册控制器.rb
def new
build_resource({})
resource.build_supp_form
respond_with self.resource
end
def create
super
end