how can I implement a cord scheduler at specific time in a day using nestjs?

Viewed 11

I am trying to scheduler a cord job at 5pm every day using nestjs.

@Cron('10 * * * * *')
  async handleCron() {
    const country = await this.countryRepo.find();
    country.map(async (value) => {
        ...doing something
    });
  }
1 Answers

You can simply use the cron expression:

@Cron('0 0 17 * * *')

Meaning at 17:00:00 every day

The @nestjs/schedule also offers cron expression alias:

So you can do:

@Cron(CronExpression.EVERY_DAY_AT_5PM)

Which is more readable

Related