Skip to content
forked from nestjs/schedule

Advanced Schedule module for Nest framework (node.js) ⏰

License

Notifications You must be signed in to change notification settings

nest-hero/schedule

 
 

Repository files navigation

Nest Logo

What NestJS default Schedule module miss?

Horizontal Scale (multiple Nest instance)

When we scale Nest in K8s or node cluster, @Cron() decorator will run many times since each Nest instance is isolated. A Nest instance can not know did cron run in others instance or not?

Retry Mechanism

If "every day cronjob" fails, we must wait a day for next cron. We better config maxRetries and turnOffWhenMaxRetries

Logging and Metric

Save cronjob history to show metric, how long does it take? how many times it retries and view history result to debug

Notification Alert

Some important cronjob need to alert when fails but we can't check console log every times

Roadmap

  • Horizontal Scale
  • Retry Mechanism
  • Logging and Metric
  • Notification Alert

Usage

Horizontal Scale (multiple Nest instance)

We use a Redis key to mark a cronjob is running by a Nest instance. Redis atomic action behavior will make sure only 1 (random) instance can run a cronjob

@Cron(CronExpression.EVERY_HOUR, {
    name: 'redis_key',
})
handleCronEveryHour() {
}

About

Advanced Schedule module for Nest framework (node.js) ⏰

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 98.1%
  • JavaScript 1.9%