Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
nest-schedule-bull
Advanced tools
A NestJS module for scheduling Bull jobs using cron expressions
A NestJS module for scheduling Bull jobs using cron expressions
npm install nest-schedule-bull
Modern applications often require reliable and efficient job scheduling to automate repetitive tasks, manage background processes, and enhance overall system performance. Nest Schedule Bull is motivated by the need for a flexible and scalable solution that seamlessly integrates with NestJS and leverages the robust capabilities of the Bull job queue.
Benefits over @nestjs/schedule
First you need to import the module in your app.module.ts
file:
import { Module } from "@nestjs/common";
import { ScheduleBullModule } from "nest-schedule-bull";
@Module({
imports: [
ScheduleBullModule.forRoot({
host: "localhost",
port: 6379,
}),
],
})
export class AppModule {}
Then you can use the @Cron()
decorator to schedule your jobs:
import { Injectable, Logger } from "@nestjs/common";
import { Cron, CronExpression } from "nest-schedule-bull";
@Injectable()
export class AppService {
private logger = new Logger(AppService.name);
@Cron(CronExpression.EVERY_10_SECONDS)
public async doSomething(): Promise<void> {
this.logger.log("Doing something...");
}
}
If you need check the status of your jobs, you can use the following decorators:
import { Injectable, Logger } from "@nestjs/common";
import {
Cron,
CronExpression,
OnQueueActive,
OnQueueCompleted,
OnQueueError,
OnQueueFailed,
OnQueueProgress,
} from "nest-schedule-bull";
@Injectable()
export class AppService {
private logger = new Logger(AppService.name);
@Cron(CronExpression.EVERY_10_SECONDS)
public async doSomething(): Promise<void> {
this.logger.log("Doing something...");
}
@OnQueueActive()
public onActive(job: Job): void {
this.logger.log(`Job ${job.id} is active`);
}
@OnQueueCompleted()
public onCompleted(job: Job): void {
this.logger.log(`Job ${job.id} is completed`);
}
@OnQueueError()
public onError(job: Job, error: Error): void {
this.logger.log(`Job ${job.id} has failed with error ${error.message}`);
}
@OnQueueFailed()
public onFailed(job: Job, error: Error): void {
this.logger.log(`Job ${job.id} has failed with error ${error.message}`);
}
@OnQueueProgress()
public onProgress(job: Job): void {
this.logger.log(`Job ${job.id} is ${job.progress}% done`);
}
}
nest-schedule-bull
is MIT licensed.
FAQs
A NestJS module for scheduling Bull jobs using cron expressions
The npm package nest-schedule-bull receives a total of 0 weekly downloads. As such, nest-schedule-bull popularity was classified as not popular.
We found that nest-schedule-bull demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.