npm.io
1.0.11 • Published 6 years ago

nestjs-rmq-test

Licence
MIT
Version
1.0.11
Deps
4
Size
25 kB
Vulns
0
Weekly
0
Stars
321

NestJS cron Module

NestJS cron package allows you easily setup cron for your controllers or services.

npm i nestjs-cron

Then register module in your root app.module

import { CronModule } from 'nestjs-cron';

@Module({
	imports: [
		// ...
		CronModule.forRoot(),
	],
})
export class AppModule {}

To use cron, decorate your class with @Scheduled() and method with @Cron()

import { Cron, Scheduled } from 'nestjs-cron';

@Scheduled()
export class MyClass {
	@Cron('* * * * * *')
	async myMethod() {
		//...
	}
}

'* * * * * *' - is a standart cron notation. In this example it will be triggered every second. Additionaly you can use options:

@Cron('* * * * * *', {
	launchOnInit: true,
	sync: true,
})
  • launchOnInit - Launch job one time right after start
  • sync - Wait for method to finish before launching next tick if your function takes more time then cron.

Keywords