R
Railway12mo ago
mtaufan

Rails Cron Job

Hi Folks, Project ID:
I have a Rails app that needs a cron job to run every 10 minutes. I've tried a few approaches. First, I used the
I have a Rails app that needs a cron job to run every 10 minutes. I've tried a few approaches. First, I used the
whenever
gem to run a scheduler script. Then i've also tried updating the crontab on the server by configuring my Procfile appropriately, but it seems like the script worker for running 'whenever update crontab' isn't being triggered.
gem to run a scheduler script. Then i've also tried updating the crontab on the server by configuring my Procfile appropriately, but it seems like the script worker for running 'whenever update crontab' isn't being triggered.
web: bundle exec rake db:migrate && bundle exec rails server -p ${PORT:-3000} worker: bundle exec whenever --update-crontab
Then, I attempted using a cron job by creating an empty service and using a rake task with the same repository, just changing the start command to run
Then, I attempted using a cron job by creating an empty service and using a rake task with the same repository, just changing the start command to run
bundle exec rake task```. This works well. However, it seems like every time the cron job runs, it rebuilds everything from scratch, which sometimes takes a long time. Is this expected, or could it be optimized with build caching? Thank you.
5 Replies
Percy
Percy12mo ago
Project ID: d6496119-3fda-4ccf-ba26-1050b4d6d823
Adam
Adam12mo ago
I believe this is expected, unfortunately. Could you instead run the job on a cron schedule in-app? As in, run the app 24/7, offload as much memory as you can, then run your job using a cron scheduling package
mtaufan
mtaufanOP12mo ago
Thank you for your suggestion. I'm interested in the idea of running the cron job within the app itself, but could you clarify what you mean by an "in-app cron schedule"? Are you suggesting the use of a specific Ruby gem or library for this purpose?
Adam
Adam12mo ago
I'm not a Ruby dev, but yes. In Python for example, you would use the package schedule
Brody
Brody12mo ago
also like to note that railway's procfile does not support worker tasks, you should use a seprate railway service just for a worker type task
Want results from more Discord servers?
Add your server