Ruby on rails 延迟的\u作业因out错误而死亡-未进行任何尝试
我有一个延迟作业,它作为一个模型方法实现(见下文)。如果我使用延迟的job守护进程,它会运行并安静地消失。没有一个作业完成,也没有找到记录的消息。但是如果我使用RAILS\u ENV=生产rake作业:一切正常 我不知道为什么,即使抛出异常,它也应该出现在日志中,但没有异常。如果逻辑有问题,那么为什么rake任务成功了呢Ruby on rails 延迟的\u作业因out错误而死亡-未进行任何尝试,ruby-on-rails,activerecord,delayed-job,Ruby On Rails,Activerecord,Delayed Job,我有一个延迟作业,它作为一个模型方法实现(见下文)。如果我使用延迟的job守护进程,它会运行并安静地消失。没有一个作业完成,也没有找到记录的消息。但是如果我使用RAILS\u ENV=生产rake作业:一切正常 我不知道为什么,即使抛出异常,它也应该出现在日志中,但没有异常。如果逻辑有问题,那么为什么rake任务成功了呢 def recalc(params) last_known = self t = nil # target(self) target_date = se
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
def recalc(参数)
最后知道的=自己
t=零#目标(自我)
目标日期=自昨天起
成功=正确
保存=-1
#迎合第一个
时隙.where(员工id:self.employee\u id).where('increduced\u on>=?',self.as\u on.).order('increduced\u on ASC')。每个do|
#环路
如果(发生日期>=目标日期),则
如果t、 零,目标日期第40天
溢出=t.bal_-40
t、 bal_sick=40
t、 bal_sick2+=溢出
t、 如果t.bal_sick2>120再次溢出,bal_sick2=120
终止
终止
除非存100英镑
elsif ts.types.include?“辛劳的
t、 bal_ot-=ts.hours.to_i
elsif ts.types.include?“假期
t、 bal_假期-=ts小时
elsif ts.types.include?“病态的
t、 bal_病假-=ts小时
终止
终止
logger.info(“Recalc已保存%d条记录”%saved)
终止
阅读之后,我发现我遗漏了“指定您的rails环境”,即rails\u ENV=production bin/delayed\u job start,默认环境似乎是development
但为什么默认环境是开发?应该是生产。如果我在发展中,我宁愿做耙子工作:工作