joelanman
12 days ago
Hi, I want to run specific scrips in my codebase in a cron job. However it seems like the cron jobs in the UI only runs the start script? Is there a way to run specific scripts, something like
npm run send-emails
6 Comments
joelanman
12 days ago
If I have to create a new service, there would be a lot of duplicate code with the main codebase. I can think of two workarounds:
- upload the same codebase but give it a different start command
- upload a light codebase that sends http requests to the main service (POST myservice.com/api/send-emails)
12 days ago
upload the same codebase but give it a different start command
Yep, this is what you wanna do, it would be another service that deploys from the same GitHub repo, you would just change the start command of that service and that's the command that will be run on the set schedule.
joelanman
12 days ago
thanks! I wonder if its worth adding that approach to the docs
12 days ago
Isn't it already? How would you improve this sentence?
Railway will look for a defined cron schedule on your service settings, and execute the start command for that service on the given schedule.
joelanman
12 days ago
Specifically the approach of uploading the same codebase, which was not intuitive to me - I'd previously deploy one codebase and run cron tasks on it. So maybe something like
If you have a main service like a website, a common approach is to deploy the same code on a second service and change the start command
12 days ago
Noted, thank you for the feedback!