工作正常,但没有发送电子邮件

时间:2013-03-11 15:33:23

标签: ruby-on-rails ruby-on-rails-3 delayed-job

我正在使用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: "noreply@yabalashdeals.com"
      def auction_start(data)
         @shared = data
         mail(:to => data['email'], :subject => "Yabalash Auction started")
      end
 end

当我运行佣金工作时:工作我得到2个工作,处理速度为4.6510 j / s,0失败...... 但没有发送电子邮件 我做了一个测试功能来检查拍卖邮件,它正常工作

这是没有错误的日志

日志/ production.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(),必须调用...现在电子邮件发送完美无缺< / p>

1 个答案:

答案 0 :(得分:0)

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

具体来说,您可能希望删除:as =&gt; :散列

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