R
Railway•14mo ago
James

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:
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 go
Jump to solution
32 Replies
Percy
Percy•14mo ago
Project ID: N/A
James
JamesOP•14mo ago
N/A
Brody
Brody•14mo ago
just create multiple services in the same project, change their start commands and then set your desired cron expression
James
JamesOP•14mo ago
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
Brody
Brody•14mo ago
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 go
James
JamesOP•14mo ago
Ah perfect, thank you so much for the help!!! Have a great day 😄
Brody
Brody•14mo ago
you too 🙂
dwaynemac
dwaynemac•14mo ago
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.
Brody
Brody•14mo ago
I like doing everything from an empty service
dwaynemac
dwaynemac•14mo ago
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
Brody
Brody•14mo ago
actually the very last thing I would do is add the repo
dwaynemac
dwaynemac•14mo ago
oh, interesting avoids rebuilds
Brody
Brody•14mo ago
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
dwaynemac
dwaynemac•14mo ago
for variables you copy-past in raw format from "source" service. ?
Brody
Brody•14mo ago
indeed
dwaynemac
dwaynemac•14mo ago
great much faster that what i was doing
Brody
Brody•14mo ago
so out of curiosity, how many cron services do you plan to run?
dwaynemac
dwaynemac•14mo ago
eventually it would be nice to have a way for multiple cron tasks to run from same service configuration 6 on current project
Brody
Brody•14mo ago
I could see that getting very confusing very fast (multiple crons per service)
dwaynemac
dwaynemac•14mo ago
I have projects with around 10-15 tasks
Brody
Brody•14mo ago
interesting
dwaynemac
dwaynemac•14mo ago
this means a project with around 20 services 🥲 quite confusing
Brody
Brody•14mo ago
yeah so it's a lose lose, it would be confusing with 15 cron services per project or 15 schedules per service
dwaynemac
dwaynemac•14mo ago
15 schedules per service is like having 15 tasks on your crontab. Isn’t it?
Brody
Brody•14mo ago
yeah but how would railway show you that all in one service in a clean and straightforward way
dwaynemac
dwaynemac•14mo ago
I imagine something like the variables UI. Just like variables, Two inputs per task: schedule and command And raw edit option.
Brody
Brody•14mo ago
I can see that getting confusing, and click to generate domain is already confusing would these be things node-cron couldn't do?
dwaynemac
dwaynemac•14mo ago
indeed on railway i'm using a similar solution, https://github.com/Rykian/clockwork , not cronjobs
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.
dwaynemac
dwaynemac•14mo ago
as I migrate projects from heroku i'm biased towards heroku's scheduler.
Brody
Brody•14mo ago
so why have 15 services if you are using clockwork?
dwaynemac
dwaynemac•14mo ago
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.
Brody
Brody•14mo ago
sounds good, I still use an in code cron scheduler for most tasks too
Want results from more Discord servers?
Add your server