【问题标题】:delayed_job dies with out error - no attempt has been madedelay_job 没有错误就死了 - 没有尝试过
【发布时间】:2014-12-08 22:17:05
【问题描述】:

我有一个作为模型方法实现的延迟工作(见下文)。如果我使用delayed_job 守护程序,它会默默地运行并死去。没有一项工作完成,也没有找到记录的消息。但如果我使用 RAILS_ENV=production rake jobs:work 一切正常。

我不知道为什么,即使抛出异常它也应该出现在日志中,但是没有。如果逻辑有问题,那么为什么 rake 作业会成功?

def recalc(params)
    last_known = self
    t = nil # target(self)
    target_date = self.as_on.yesterday 
    success = true
    saved = -1 
    # cater for the first one
    TimeSlot.where(employee_id:self.employee_id).where('incurred_on >= ?', self.as_on).order('incurred_on ASC').each do |ts|
        # loop
        if (ts.incurred_on >= target_date) then
            if !t.nil? && target_date.day <=7 # roll over to a new month
                t.bal_sick += 4 # add 4 days
                if t.bal_sick > 40 
                    overflow = t.bal_sick-40
                    t.bal_sick = 40
                    t.bal_sick2 += overflow
                    t.bal_sick2 = 120 if t.bal_sick2 > 120 # overflow again
                end
            end
            unless saved<0
                success = t.save 
                last_known = t
            end
            if success
                saved += 1
                t = target(last_known)
                target_date = t.as_on
            else
                logger.warn("Recalc cannot saved a record for #{t.errors.first}")
                logger.warn(t.inspect)
                return
            end
        end
        if ts.types.include? 'overtime'
            t.bal_ot += ts.hours.to_i
            t.bal_ot = 100 if t.bal_ot >100 
        elsif ts.types.include? 'toil'
            t.bal_ot -= ts.hours.to_i
        elsif ts.types.include? 'vacation'
            t.bal_vacation -= ts.hours
        elsif ts.types.include? 'sick1'
            t.bal_sick -= ts.hours
        end
    end
    logger.info("Recalc saved %d records"% saved)
end

【问题讨论】:

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


    【解决方案1】:

    看了https://github.com/collectiveidea/delayed_job/wiki/Common-problems后发现漏掉了“指定你的rails环境”,即RAILS_ENV=production bin/delayed_job start,默认环境好像是开发。

    但为什么默认环境是开发环境?应该是生产。如果我在开发中,我宁愿做一些工作:工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2011-06-04
      • 2021-12-05
      • 1970-01-01
      • 2010-12-31
      • 1970-01-01
      • 2012-03-24
      相关资源
      最近更新 更多