Cron jobs/scheduler on Fly.io?

Hey @Brad, you’re guide on using Crontab with Supercronic was helpful to get started. I’ve got the “hello world!” example up and running on v2 of fly.

I thought the following would run the rake task scrape:test every 5 minutes:

*/5 * * * * /bin/bash -l -c "cd /app && RAILS_ENV=production bin/bundle exec rake scrape:test"

But I get the following error:

level=info msg="/usr/bin/env: ‘ruby’: No such file or directory" channel=stderr iteration=2 job.command="/bin/bash -l -c \"cd /app && RAILS_ENV=production bin/bundle exec rake scrape:test\"" job.position=1 job.schedule="*/5 * * * *"

level=error msg="error running command: exit status 127" iteration=2 job.command="/bin/bash -l -c \"cd /app && RAILS_ENV=production bin/bundle exec rake scrape:test\"" job.position=1 job.schedule="*/5 * * * *"

Any ideas how I would run a rake task?

Just to play devil’s advocate… the arguments in favor of using Docker are good. On the other hand, what a complicated way to set up a cron job! I want to specify cron jobs on the server where they’re run, not in my localhost where the paths don’t even match. Having to write them locally, build an image, deploy it, only to find you need to change something, is a whole lot of overhead we never had before. I would vastly prefer a command like e.g.

fly cron set "* 5 * * * /path/to/script"

6 Likes

If anyone is still having issues setting up Cron, this project may be useful:

https://community.fly.io/t/launch-and-manage-cron-jobs-effortlessly