nest-hero / schedule

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

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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) ⏰

https://nestjs.com

License:MIT License


Languages

Language:TypeScript 98.1%Language:JavaScript 1.9%