Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nest-schedule-bull

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nest-schedule-bull

A NestJS module for scheduling Bull jobs using cron expressions

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Nest schedule bull

A NestJS module for scheduling Bull jobs using cron expressions

Installation

npm install nest-schedule-bull

Motivation

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

  • Distributed Job Processing: Nest Schedule Bull, built on top of Bull, supports distributed job processing. This is particularly beneficial in scenarios where tasks need to be executed across multiple nodes or instances.
  • Enhanced Scalability: Nest Schedule Bull Leveraging the scalability of Bull, Nest Schedule Bull allows you to scale your job processing horizontally, ensuring optimal performance as your application grows.
  • Robust Job Monitoring: With the integration of Bull's features, Nest Schedule Bull provides extensive job monitoring capabilities. This includes real-time tracking of job status, progress, and error handling, empowering you with in-depth insights into your scheduled tasks.
  • Cron Expression Flexibility: Nest Schedule Bull offers a wide range of cron expression options, allowing you to schedule jobs with precision and flexibility. This is essential for executing tasks at specific intervals or implementing complex scheduling patterns.

Usage

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`);
  }
}

Stay in touch

License

nest-schedule-bull is MIT licensed.

Keywords

FAQs

Package last updated on 30 Dec 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc