包含rufus调度程序的代码:
<start_index_of_terms_span>59
调用调度程序的代码:
def checkout_timer time, id, lpn
scheduler = Rufus::Scheduler.new
time_to_do = time + 1.minute
Rails.logger.info "time_to_do: #{time_to_do}, id: #{id}"
scheduler.at time_to_do do
Rails.logger.info "hello, it's #{Time.now}"
reservation = Reservation.find(id)
if reservation&&reservation.status == 'Reserved'
reservation.destroy
Car.where(:lpn => lpn).update_all(:status => "Available")
notification = Notification.new(:email => reservation.email, :message => 'You do not check out the car on time !')
notification.save
end
end
end
@ reservation.expect_return_time从
获取其值if user && @reservation1 == [] && @reservation.save
return_timer @reservation.expect_return_time, @reservation.id, @reservation.lpn
@reservation.update_attribute(:expect_start_time, Time.now)
@car = Car.find_by_lpn(@reservation.lpn)
@car.update_attribute(:status, "Checkout")
format.html {redirect_to @car, notice: 'Rent successfully.'}
# format.json { render :show_reserve, status: :reserved, location: @reservation }
它在我的本地计算机上正常运行。我记得昨天在heroku上没有问题。然而,今天在heroku上发生了这个奇怪的问题。
更新
答案 0 :(得分:0)
强制你的Heroku在版本1.0.5使用宝石“et-orbi”。
请注意,每次调用checkout_timer
时启动一个新的Rufus-Scheduler实例都是浪费资源。它将你的rufus-scheduler实例暴露给垃圾收集,如果它在作业指定的时间之前发生,则作业不会触发。
更新2017-10-07
rufus-scheduler使用的gem“et-orbi”版本1.0.7包含对此问题的修复。