2014-12-07 114 views
0

我有一個延遲的工作,它作爲模型方法實現(見下文)。如果我使用delayed_job守護進程,它會無聲無息地死亡。沒有一項工作完成,沒有找到記錄的信息。但是如果我使用RAILS_ENV =生產耙子工作:工作一切正常。delayed_job死亡失敗 - 沒有嘗試

我不知道爲什麼,即使拋出異常,它應該出現在日誌中,但沒有。如果邏輯有問題,那麼爲什麼耙取工作成功了?

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 

回答