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

Get the cron expression from the config too #1439

Closed
1 task done
peixotoleonardo opened this issue Oct 6, 2023 · 0 comments
Closed
1 task done

Get the cron expression from the config too #1439

peixotoleonardo opened this issue Oct 6, 2023 · 0 comments

Comments

@peixotoleonardo
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 would like load cron expression from a config, without implement a dynamic cron job.

Describe the solution you'd like

import { Module } from '@nestjs/common';
import { ScheduleModule } from '@nestjs/schedule';

@Module({
  imports: [
    ScheduleModule.forRoot({
       crons: {
           'task-service.handleCron': '45 * * * * *',
       }
    })
  ],
})
export class AppModule {}
import { Injectable, Logger } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';

@Injectable()
export class TasksService {
  private readonly logger = new Logger(TasksService.name);

  @Cron('task-service.handleCron')
  handleCron() {
    this.logger.debug('Called when the current second is 45');
  }
}

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

I believe that using cron expressions in hard code is not useful because there are use cases where the cron expression could be changed, and defining it as a config will facilitate that change, although we can register dynamically using schedule register, I believe that having this via decorator would be really useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant