Handling guards on CRON
damiankoper opened this issue · comments
Is there an existing issue that is already proposing this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe it
I have an issue when I have multiple replicas of the Nest app and I want to run CRON jobs only on one of them. I do not want to create additional not replicated services. I do not want to create if
in each function because that's what guards are for.
Describe the solution you'd like
I have two ideas:
- Preventing CRON registration by guards alongside with
@Cron
decorator.- Or add a guard as CRON decorator's argument or sth
🐱
- Or add a guard as CRON decorator's argument or sth
- Preventing each CRON execution by running guard onTick (better solution)
Teachability, documentation, adoption, migration strategy
Non-breaking
What is the motivation / use case for changing the behavior?
I've got multiple jobs that have to be run only once but I still want to use a single Nest app with multiple replicas.
I could try to make a PR if that's ok.
I do not want to create additional not replicated services. I do not want to create if in each function because that's what guards are for.
That's precisely where you should services (providers). (Nest's) Guards don't seem to fit here.
Thanks for your suggestion!
If you think your request could live outside Nest's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.