Cron job not working in Whenever gem

后端 未结 4 2233
轮回少年
轮回少年 2020-12-04 10:35

I have an application that contains a bunch of tasks, and every day I want to run a cron job that creates a DayTask for each Task in the database. A Task has_many DayTasks a

相关标签:
4条回答
  • 2020-12-04 10:58

    Finally I have solved how to run the gem Whenever. It's working good on production, but not in development mode (I think that to working good in dev mode you must do some tricks).

    Then, these are the processes to do:

    1. install the gem
    2. write your scheduler.rb file
    3. push to the remote server
    4. login to the remote server (for example with ssh)
    5. see if whenever is good uploaded by running in terminal: whenever
    6. update whenever crontab by running: whenever --update-crontab
    7. restart the server crontab (for example in Ubuntu server): sudo service cron restart
    8. check if crontab is good implemented on the server: crontab -l

    That's it!

    Personally, I prefer to set up my crons directly from the server:

    1. Edit the crontab: crontab -e
    2. Append my cron (e.g. every day at 5:00 AM - can be little different for not-Linux-based server):
      0 5 * * * /bin/bash -l -c 'cd /path_to_my_app/current && RAILS_ENV=production bundle exec rake my_cron_rake'
    3. Check if good implemented: crontab -l
    4. Done
    0 讨论(0)
  • 2020-12-04 11:00

    Try to execute the whenever generated command directly from terminal or add the following line MAILTO=your@emailadress.com to your crontab.

    0 讨论(0)
  • 2020-12-04 11:13

    You have to actually register the job with the crontab by running:

    whenever --update-crontab

    Also if you're trying to get jobs running locally, add :environment => "development" to your task

    runner "MyTask.some_action", :environment => "development"

    0 讨论(0)
  • 2020-12-04 11:17

    if whenever command gives you -bash: whenever: command not found, try bundle exec whenever

    0 讨论(0)
提交回复
热议问题