delayed_job在没有错误的情况下死亡 - 没有尝试过

时间:2014-12-07 15:28:58

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

我有一个延迟的工作,作为模型方法实现(见下文)。如果我使用delayed_job守护进程,它会无声地运行并死亡。没有一个工作完成,也没有找到任何记录的消息。但是,如果我使用RAILS_ENV =生产佣金工作:工作一切正常。

我不知道为什么,即使抛出异常,它也应该出现在日志中,但没有。如果逻辑出现问题,那么为什么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

1 个答案:

答案 0 :(得分:0)

在阅读https://github.com/collectiveidea/delayed_job/wiki/Common-problems后,我发现我已经错过了#34;指定你的rails环境&#34;,即RAILS_ENV =生产箱/ delayed_job启动,默认环境似乎是开发。< / p>

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

相关问题