Could anyone give me a tip how to set up CRON jobs for a Rails app that's running on Amazon EC2 (Ubuntu)?
Trying to find some tutorials or tips how to make it work, but still without any success. Thank you
Try creating a model method which execute a task for your crondjob. You can execute the script by using rails runner.
rails runner 'User.deliver_reminder_emails!'
The whenever gem can even do fancier stuff: https://github.com/javan/whenever
This worked out to be rather tricky for me, as the ELB-EC2 instance was trying to run a cron job as root, which seemed to result in a different set of permissions, bundle, etc.
It's a bit hacky, but this worked:
sudo su ec2-user bin/bash -lc "cd /var/app/current && /opt/rubies/ruby-2.1.8/bin/bundle exec/bundle exec rails runner -e your_env \"Model.do_something\""
Basically, su to the user that usually runs rails, and explicitly state the paths for bundle.
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.