2013-03-11 59 views
0

我使用的delayed_job(3.0.1)和delayed_job_active_record(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: "[email protected]" 
     def auction_start(data) 
     @shared = data 
     mail(:to => data['email'], :subject => "Yabalash Auction started") 
     end 
end 

时我运行耙作业:工作我得到2个工作在4.6510焦耳/秒处理,0失败... 但没有电子邮件发送 我犯了一个测试功能查看拍卖邮件和它的工作正确

这里是木头,没有错误

日志/ production.log

Sent mail to [email protected] (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()必须,如果你使用排队()被称为这个问题的解决。现在的电子邮件发送完美

+0

检查你的日志,并粘贴如果你得到任何错误? – abhas 2013-03-11 15:37:56

+0

您可以将执行方法从延迟作业中取出并尝试使用相同的SQL和参数吗? – 2013-03-11 15:56:18

+0

我做了一个测试控制器/方法来检查拍卖邮件,它正常工作。 ,并有一个联系我们发送邮件,并使用MessageMailer,它只是使用**邮件()**,它是完美的工作 – 2013-03-11 15:59:08

回答

0

它在我看来像你的延迟工作代码是错误的。尝试将其移出可以从控制台调用的方法。

具体而言,您可能希望删除:as =>:hash。

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 do |row| 
    AuctionMailer.delay.auction_start(row) 
end 

+0

这是不正常的测试代码(不使用:作为=>:散列) DEF执行 AuctionMailer.auction_start( )。寄存器 结束 – 2013-03-11 16:22:29

相关问题