Best Way to Run a Weekly Cron Job
Use case:
I need to poll an external API during several windows throughout the week. The times change each week and no two will be the same (or very rarely). I know what the upcoming week's times will be by polling an endpoint at a particular time in the current week.
This cron job of mine requests data from an external API to compare to data in my networked database and if it detects changes it does things and then updates the database.
Current state:
Currently, I have the cron scripts start up and queue in my Express app after it deploys but they do not run on schedule in Railway, nor at all. The jobs run at the appropriate time locally and works with my local services without error.
Question:
Curious to know the best path ahead or perhaps what I'm doing incorrectly when starting the jobs on Railway. I'd prefer not to but if I have to create a separate service for the cron and use Railway's cron settings in the service settings I'll go down that path.
Thanks!
Solution:Jump to solution
id recommend creating another service, but continue using bree, separate bree from your express app
7 Replies
Project ID:
db989257-d5bb-4cba-acd6-bc0aa22606a5
db989257-d5bb-4cba-acd6-bc0aa22606a5
just so i understand correctly, youre currently using an in code cron schedular right now?
Yes I'm using https://www.npmjs.com/package/bree
Solution
id recommend creating another service, but continue using bree, separate bree from your express app
Awesome, thanks Brody.
no prob!