a year ago
In documentation, it is mentioned "If you are already using a scheduling library or system in your service such as node-cron or Quartz, Railway cron jobs are a substitute of them that allows you to save resources between executions."
When I searched for example, all examples use libraries to run cronjob. However, in current railway there is cronjob deployment option but no explainaiton how to create the service.
My scenario is like this, I created a DB service (MySQL) using docker image. I want to run mysqldump every day at 1:00 am. How to create a backup service to accomplish this?
1 Replies
a year ago
Hello,
When using libraries like node-cron you would have node-cron run your desired function on your set schedule in code, and that code keeps running 24/7.
When using Railway's cron scheduler you need to have an entry point script like start.js (that's defined in the start command or start script in the package.json) that when ran does the desired task and exits when done, then you can set your schedule in the service settings and Railway will run a deployment on your set schedule, your start.js gets ran and does it's task and exits.
Railway's native scheduler is better in a lot of scenarios because you are only charged for the resources your task used for the duration it ran for, you aren't charged for idle resources like you are when using node-cron or similar tasks.
As for backing up mysql on a set schedule there are a few templates that can do that for you here - https://railway.app/templates
Though I don't think any of them utilize Railway's native scheduler and all use some kind of in-code scheduler.