“Whenever” gem running cron jobs on Heroku

丶灬走出姿态 提交于 2019-11-27 19:16:39

问题


I created an app that uses the whenever gem. The gem creates cron jobs. I got it working locally but can't seem to get it working on heroku cedar. What's the command to do this?

running:

heroku run whenever --update-crontab job1

doesn't work


回答1:


Short answer: use the scheduler add-on: http://addons.heroku.com/scheduler

Long answer: When you do heroku run, we

  1. spin up a dyno
  2. put your code on it
  3. execute your command, wait for it to finish
  4. throw the dyno away

Any changes you made to crontab would be immediately thrown away. Everything is ephemeral, you cannot edit files on heroku, just push new code.




回答2:


You need to add Heroku Scheduler addon.

You can add it directly from your dashboard or using following commands:

  1. install the add-on:

    heroku addons:create scheduler:standard
    
  2. Create a rake task in lib/tasks

    # lib/tasks/scheduler.rake
    task :send_reminders => :environment do
      User.send_reminders
    end
    
  3. Schedule job

    • Visit Heroku Dashboard
    • Open your app
    • Select Scheduler from add-ons list
    • Click Add Job, enter a task and select frequency.

      e.g. Add rake send_reminders, select "Daily" and "00:00" to send reminders every day at midnight.



来源:https://stackoverflow.com/questions/8619754/whenever-gem-running-cron-jobs-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!