简体   繁体   中英

Rails - Background job (countdown)

i did countdown for time remaining in ruby. But can't figured out how to run it in background, because when i run it in controller or helper it's starting before the view is loaded, so the countdown have to be finished then the view is loaded.

So i need to run it on background with a low priority because i need to save that updated time in DB.(function is working properly)

I found this gem RESQUE , it's good for it or better way is do it manualy?

I'm quite new in ruby, so i appreciate any advice with that.

THIS IS MY JOB

@commits.each do |t|
  timer_date = t.updated_at + 6000
    while Time.now < timer_date
      timeo = Time.at(timer_date.to_i - Time.now.to_i)
      t.remain = timeo
      t.save
      sleep 1
    end
end

您可以使用sidekiq gem https://github.com/mperham/sidekiq进行后台处理。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM