Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hanfengsan/nestjs-agenda
Agenda for Nest.js, a NestJS distributed job scheduler based on MongoDB
https://github.com/hanfengsan/nestjs-agenda
agenda cron javascript job-processor job-scheduler nest nestjs nodejs scheduler task
Last synced: 3 months ago
JSON representation
Agenda for Nest.js, a NestJS distributed job scheduler based on MongoDB
- Host: GitHub
- URL: https://github.com/hanfengsan/nestjs-agenda
- Owner: hanFengSan
- License: mit
- Created: 2019-09-16T02:48:35.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-30T18:19:45.000Z (9 months ago)
- Last Synced: 2024-10-31T12:03:26.874Z (3 months ago)
- Topics: agenda, cron, javascript, job-processor, job-scheduler, nest, nestjs, nodejs, scheduler, task
- Language: TypeScript
- Homepage:
- Size: 40 KB
- Stars: 21
- Watchers: 2
- Forks: 13
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nestjs-agenda
[Agenda](https://github.com/agenda/agenda) module for [Nestjs](https://github.com/nestjs/nest)Agenda version is `^3.1.0`
# Installation
```
npm install nestjs-agenda
```# Usage
**1. Import `AgendaModule`:***Sync register*:
```TypeScript
import { AgendaModule } from 'nestjs-agenda';@Module({
imports: [AgendaModule.register({ db: { address: 'mongodb://xxxxx' }})], // Same as configuring an agenda
providers: [...],
})
export class FooModule {}
```
*Async register*:
```TypeScript
import { AgendaModule } from 'nestjs-agenda';@Module({
imports: [
AgendaModule.registerAsync({
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):**
```TypeScript
import { Injectable } from '@nestjs/common';
import { AgendaService } from 'nestjs-agenda';@Injectable()
export class FooService {
constructor(private readonly agenda: AgendaService) {
// define a job, more details: [Agenda documentation](https://github.com/agenda/agenda)
this.agenda.define('TEST_JOB', { lockLifetime: 10000 }, this.testJob.bind(this));
// schedule a job
this.agenda.schedule('10 seconds from now', 'TEST_JOB', {});
}private async testJob(job: any, done: any): Promise {
console.log('a job');
await job.remove();
done();
}
}
```