2013-03-11 28 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

相關問題