How to maintain node-cron in my NestJS project when setting more replicas
Hi! I have a project deployed in railway in NestJS and it has some cron jobs on it. I was just wondering once I scale in more replicas in a future, how should I treat those cronjobs? Is there any way I can know for example the replica number in an env variable so I can only run the cron on one replica? There's any walkaround rather than doing another service? Thank you π
8 Replies
Project ID:
N/A
Project ID:
N/A
N/A
a separate single service that runs the cron job is the way to go
Hmm I guess then if there are some shared modules the only way is to use nestJS microservices in a monorepo or smth like this..
The env thing sound easier haha
maybe that way you could even use railways cron scheduler so that there would be zero resources when the task isn't running
Hmm maybe its a worst option, but for the beginning until separating the services I could have a cron that just calls an endpoint in my service and then it would be done in one of the replicas. Pretty ugly but until we separate services could work
well separating the cron service out if definitely the best way to go about this problem!