Multiple cronjobs
How would I run multiple cronjobs at different times from the same typescript project?
I want to avoid a new project for each job and instead write multiple scripts in one project that each get run at different times but share functions/ types.
Solution:Jump to solution
yeah you can totally do that from one repo, though you would of course need multiple railway services for each cron job, just have some start scripts in your package.json that start the code youd want to run on the cron job, then in the cron service change the start command to
npm run <the start command for the job you want to run>
and then set the cron expression, and away you go32 Replies
Project ID:
N/A
N/A
just create multiple services in the same project, change their start commands and then set your desired cron expression
Sorry, when I said "project" I meant typescript project, not railway project haha.
My desired outcome would be 1 github repo with all my cronjobs that get deployed to railway.
Solution
yeah you can totally do that from one repo, though you would of course need multiple railway services for each cron job, just have some start scripts in your package.json that start the code youd want to run on the cron job, then in the cron service change the start command to
npm run <the start command for the job you want to run>
and then set the cron expression, and away you goAh perfect, thank you so much for the help!!!
Have a great day 😄
you too 🙂
considering this solution for multiple jobs. is there a quick/easy way to create multiple services that are exactly the same except for their startCommand?
it seems like a task one would do frequently for cronjobs.
I like doing everything from an empty service
so you'd:
1. create service
2. set github repo
3. set railway config path
4. set startCommand
5. set cron schedule
for each cron task
actually the very last thing I would do is add the repo
oh, interesting
avoids rebuilds
that was I know the service has all the settings set so that my build is successful the first time
exactly
hitting that cancel button is a pain
for variables you copy-past in raw format from "source" service.
?
indeed
great
much faster that what i was doing
so out of curiosity, how many cron services do you plan to run?
eventually it would be nice to have a way for multiple cron tasks to run from same service configuration
6 on current project
I could see that getting very confusing very fast (multiple crons per service)
I have projects with around 10-15 tasks
interesting
this means a project with around 20 services 🥲
quite confusing
yeah so it's a lose lose, it would be confusing with 15 cron services per project or 15 schedules per service
15 schedules per service is like having 15 tasks on your crontab.
Isn’t it?
yeah but how would railway show you that all in one service in a clean and straightforward way
I imagine something like the variables UI.
Just like variables, Two inputs per task:
schedule and command
And raw edit option.
I can see that getting confusing, and click to generate domain is already confusing
would these be things node-cron couldn't do?
GitHub
GitHub - Rykian/clockwork: A scheduler process to replace cron.
A scheduler process to replace cron. Contribute to Rykian/clockwork development by creating an account on GitHub.
as I migrate projects from heroku i'm biased towards heroku's scheduler.
so why have 15 services if you are using clockwork?
i have 15 tasks on heroku's scheduler. i converted that into one service with this clockwork
But when cronjobs were launched i started looking into them to see if this would be a better solution.
for the time being using clockwork or node-cron seems better suited for this project.
sounds good, I still use an in code cron scheduler for most tasks too