nestjs / schedule

Schedule module for Nest framework (node.js) ⏰

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get the cron expression from the config too

peixotoleonardo 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 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 is changed frequently, 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.

Thanks for your suggestion!

There are no plans to implement it in the foreseeable future.

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.