Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling guards on CRON #984

Closed
1 task done
damiankoper opened this issue Jul 15, 2022 · 1 comment
Closed
1 task done

Handling guards on CRON #984

damiankoper opened this issue Jul 15, 2022 · 1 comment

Comments

@damiankoper
Copy link

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:

  1. Preventing CRON registration by guards alongside with @Cron decorator.
    • Or add a guard as CRON decorator's argument or sth 🐱
  2. 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.

@kamilmysliwiec
Copy link
Member

kamilmysliwiec commented Jul 18, 2022

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.

@nestjs nestjs locked and limited conversation to collaborators Jul 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants