我正在使用延迟作业(3.0.1)和延迟作业活动记录(0.4.3)在触发此操作时基于另一个操作发送电子邮件
Delayed::Job.enqueue(MailingJob.new(@auction.id) , 0 , date)
这是邮寄工作
class MailingJob < Struct.new(:auction_id)
def perform
sql = "select a.id , u.fname , u.lname , u.email , p.name
from auctions a
join products p on a.product_id = p.id
join auction_followers af on a.id = af.auction_id
join users u on af.user_id = u.id
where a.id = #{auction_id}"
result = ActiveRecord::Base.connection.execute(sql)
result.each(:as => :hash) do |row|
AuctionMailer.delay.auction_start(row)
end
end
end
这是 AuctionMailer
class AuctionMailer < ActionMailer::Base
default from: "noreply@yabalashdeals.com"
def auction_start(data)
@shared = data
mail(:to => data['email'], :subject => "Yabalash Auction started")
end
end
当我运行 rake jobs:work 时,我得到 2 个以 4.6510 j/s 的速度处理的工作,0 个失败......但没有发送电子邮件我做了一个测试功能来检查拍卖邮件,它工作正常
这是没有错误的日志
日志/生产.log
Sent mail to hesham.kanany@gmail.com (99ms)
Rendered text template (0.0ms)
Completed 200 OK in 288ms (Views: 1.1ms | ActiveRecord: 1.3ms)
日志/delayed_job.log
MaillingJob completed after 0.0035
1 jobs processed at 93.1503 j/s, 0 failed ...
完成 抱歉没有发布这个问题的解决方案我想出了.deliver()如果你使用enqueue()必须调用它......现在电子邮件发送完美