@sigmaott/nestjs-agenda
TypeScript icon, indicating that this package has built-in type declarations

3.1.1 • Public • Published

nestjs-agenda

This repo base on nestjs-agenda and wrap decorator agenda job defined Agenda module for Nestjs

Agenda version is ^4.1.3

Installation

npm i @sigmaott/nestjs-agenda

Dependencies

Thank for @golevelup build the easy way to implement Dynamic Module and Discovery Module

Usage

1. Import AgendaModule:

Sync register:

import { AgendaModule } from '@sigmaott/nestjs-agenda';

@Module({
  imports: [AgendaModule.forRoot(AgendaModule, { db: { address: 'mongodb://xxxxx' }})], // Same as configuring an agenda
  providers: [...],
})
export class FooModule {}

Async register:

import { AgendaModule } from '@sigmaott/nestjs-agenda';

@Module({
  imports: [
    AgendaModule.forRootAsync(AgendaModule, {
      imports: [ConfigModule],
      useFactory: async (config: ConfigService) => ({
        db: { address: config.get('MONGODB_URI') },
      }),
      inject: [ConfigService],
    }),
  ],
  providers: [...],
})
export class FooModule {}

2. Inject AgendaService (AgendaService is a instance of Agenda):

import { Injectable } from '@nestjs/common';
import { AgendaService } from '@sigmaott/nestjs-agenda;

@Injectable()
export class FooService {
  constructor(private readonly agenda: AgendaService) {
    // schedule a job
    this.agenda.schedule('10 seconds from now', 'TEST_JOB', {});
  }

  @AgendaHandler({
    name: 'TEST_JOB',
    lockLifetime: 10000
  })
  private async testJob(job: any, done: any): Promise<void> {
    console.log('a job');
    await job.remove();
    done();
  }
}

Readme

Keywords

Package Sidebar

Install

npm i @sigmaott/nestjs-agenda

Weekly Downloads

402

Version

3.1.1

License

MIT

Unpacked Size

110 kB

Total Files

27

Last publish

Collaborators

  • phongthien
  • tiennv173
  • vietanha34