6 months ago
I've noticed the cron job gets triggered each time a new deployment kicks in. Is there a way to disable this behavior?
11 Replies
6 months ago
I think there's something off with your cron schedule itself? It says this but it seems to be running daily?
Crons should not run on deploy
Attachments
Status changed to Awaiting User Response Railway • 6 months ago
6 months ago
I've just validated that crons do not run on deploy normally. You might want to resolve the issue with the cron syntax and try again
6 months ago
Thanks for the response. I may not have phrased my question clearly. As the documentation states, Railway runs the start command on the defined schedule. There is no problem with that. But the issue is that the start command also runs on every new deployment. While this behavior is fine for servers, I want the cron job to run only when triggered by the schedule, not on deployment
Status changed to Awaiting Railway Response Railway • 6 months ago
6 months ago
Hmmm, it looks like your cron job isn't exiting cleanly when the job is done, which means it's only terminating when the container exits for another reason.
You can see in the attached runs that your container only exited because the next cron run killed the previous container. Your cron should send the SIGINT signal to cleanly exit the container when the cronjob is done successfully or when it enters an error state.
I suspect this might be why you're seeing the job execute in a strange way.
You can see more in our cron docs: https://docs.railway.com/reference/cron-jobs
Attachments
Status changed to Awaiting User Response Railway • 6 months ago
echohack
Hmmm, it looks like your cron job isn't exiting cleanly when the job is done, which means it's only terminating when the container exits for another reason.You can see in the attached runs that your container only exited because the next cron run killed the previous container. Your cron should send the SIGINT signal to cleanly exit the container when the cronjob is done successfully or when it enters an error state.I suspect this might be why you're seeing the job execute in a strange way.You can see more in our cron docs: https://docs.railway.com/reference/cron-jobs
6 months ago
Thanks for looking into this. I believe the issue is unrelated to what you described. I’ve tested multiple templates, including Railway’s managed function service, and they all behave the same — the log message prints "stop container" until a new deployment is completed.
Circle back to the issue I raised, I might be onto something after messing around for a while: my cron schedule was defined in the config file instead of set through the UI (see attached screenshot for my config file), and I had been seeing the start command being executed on every deployment. After removing the cron schedule from the config file and configuring it through the UI instead, new deployments no longer trigger the start command. This seems like a bug to me unless I'm misusing the config file.
To reproduce what I've been experiencing:
Fork this template from the marketplace: https://railway.com/deploy/mS2kAe (or any other cron templates)
Add a config file with a start command (e.g.,
bun run index.ts) and a cron schedule.Deploy the repo — you'll see the start command runs in deploy logs.
Make any change and push to
main— the start command runs again
Attachments
Status changed to Awaiting Railway Response Railway • 6 months ago
6 months ago
Oh interesting. Okay, so, this only occurs through the config as code? Would make sense why I couldn't replicate it
Please confirm and I'll file the ticket (then, please don't use the config as code for the meantime since...that will cause your issue)
Status changed to Awaiting User Response Railway • 6 months ago
jake
Oh interesting. Okay, so, this only occurs through the config as code? Would make sense why I couldn't replicate itPlease confirm and I'll file the ticket (then, please don't use the config as code for the meantime since...that will cause your issue)
6 months ago
Yes, I think so, I'm able to replicate that in other repos too.
Status changed to Awaiting Railway Response Railway • 6 months ago
6 months ago
Hello!
We're acknowledging your issue and attaching a ticket to this thread.
We don't have an ETA for it, but, our engineering team will take a look and you will be updated as we update the ticket.
Please reply to this thread if you have any questions!
Status changed to Awaiting User Response Railway • 6 months ago
Status changed to Solved jake • 6 months ago
5 months ago
🛠️ The internal ticket When using Config-as-Code, Cronjob Fires on deployment has been marked as in progress.
5 months ago
✅ The internal ticket When using Config-as-Code, Cronjob Fires on deployment has been marked as completed.
