nestjs / schedule

Schedule module for Nest framework (node.js) ⏰

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

  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.

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.