a month ago
I have simple Astro app, it has api route that when triggered can send daily emails.
I could extract it to script potentially.
Project has already a cron job setting, but it just configures frequency, not what will be executed. Looking at the docs, this is never explained, so I assume it is trivial.
Can someone help me understand this. How would I go about running /api/daily_email vs bun send_daily_email.ts ?
Thanks in advance.
Pinned Solution
a month ago
Hey, Railway runs your service on the specified cron schedule. If you want to run bun send_daily_email.ts, then it is best create another service with the same source but with a custom start command (bun send_daily_email.ts) and specify the cron schedule. Another way, would be utilizing a Railway function that calls your endpoint with a specified cron schedule.
6 Replies
a month ago
Hey, Railway runs your service on the specified cron schedule. If you want to run bun send_daily_email.ts, then it is best create another service with the same source but with a custom start command (bun send_daily_email.ts) and specify the cron schedule. Another way, would be utilizing a Railway function that calls your endpoint with a specified cron schedule.
uxuz
Hey, Railway runs your service on the specified cron schedule. If you want to run bun send_daily_email.ts, then it is best create another service with the same source but with a custom start command (bun send_daily_email.ts) and specify the cron schedule. Another way, would be utilizing a Railway function that calls your endpoint with a specified cron schedule.
a month ago
Oh I see. So if I set cron job on my main app, it would actually run
at the specified time now always. I see, this makes sense.
Thank you, I knew it was something simple.
desireco
Oh I see. So if I set cron job on my main app, it would actually run at the specified time now always. I see, this makes sense.Thank you, I knew it was something simple.
a month ago
You most likely don't want to run the cron job on the main app, since that would be an Astro app which would technically never terminate? Cron jobs will only run if the previous instance has been terminated (exited). Here is the documentation regarding it for more clarity: https://docs.railway.com/reference/cron-jobs.
Status changed to Solved sam-a • about 1 month ago
uxuz
Hey, Railway runs your service on the specified cron schedule. If you want to run bun send_daily_email.ts, then it is best create another service with the same source but with a custom start command (bun send_daily_email.ts) and specify the cron schedule. Another way, would be utilizing a Railway function that calls your endpoint with a specified cron schedule.
a month ago
One more thing. Since it is npm task, just github repo and run npm. Is there any advantage of running as function? Maybe I should read up more on a docs. If you don't mind explaining this, it would be awesome. And thanks a bunch.
Status changed to Awaiting Railway Response Railway • about 1 month ago
desireco
One more thing. Since it is npm task, just github repo and run npm. Is there any advantage of running as function? Maybe I should read up more on a docs. If you don't mind explaining this, it would be awesome. And thanks a bunch.
a month ago
Think of Railway function as a single file run with Bun, it's purpose is to run small and simple tasks. https://docs.railway.com/reference/functions. Complex tasks shouldn't be a function, but if all you need is to have a function to call an endpoint on a cron schedule, then a Railway function would be a good fit.
uxuz
Think of Railway function as a single file run with Bun, it's purpose is to run small and simple tasks. https://docs.railway.com/reference/functions. Complex tasks shouldn't be a function, but if all you need is to have a function to call an endpoint on a cron schedule, then a Railway function would be a good fit.
a month ago
thank you, helped me a lot
Status changed to Solved desireco • about 1 month ago

