Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vinks/nest-agenda-jobs
Agenda task wrapper module for Nestjs
https://github.com/vinks/nest-agenda-jobs
Last synced: 4 days ago
JSON representation
Agenda task wrapper module for Nestjs
- Host: GitHub
- URL: https://github.com/vinks/nest-agenda-jobs
- Owner: vinks
- Created: 2018-12-20T11:18:02.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-06T09:39:46.000Z (2 months ago)
- Last Synced: 2024-10-13T15:13:22.608Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 1.01 MB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Description
This is a [Agenda](https://github.com/agenda) task wrapper module for [Nest](https://github.com/nestjs/nest).
## Installation
```bash
$ npm i --save nest-agenda-jobs
```## Quick Start
```ts
import { Injectable } from '@nestjs/common';
import { Task } from 'nest-agenda-jobs';@Injectable()
export class AppTasks {
@Task({ name: 'justATest' })
justATest(job: Agenda.Job, done) {
const result: number = (job.attrs.data || []).reduce((a, b) => a + b);setTimeout(() => {
done(null, result);
}, 900);
}
}import { Controller, Get } from '@nestjs/common';
import { AgendaService } from 'nest-agenda-jobs';
import { AppTasks } from './app.tasks';@Controller('app')
export class AppController {
constructor(
private readonly agendaService: AgendaService,
private readonly tasks: AppTasks,
) {}@Get()
public async runTask() {
const data = [1, 2, 3];await this.agendaService.createJob(this.tasks.justATest, {
type: 'now',
autoRemove: false,
}, data);return true;
}
}import { Module, OnModuleInit } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { AgendaModule, AgendaTaskRegisterService, AgendaService } from 'nest-agenda-jobs';
import { AppTasks } from './app.tasks';
import { AppController } from './app.controller';@Module({
imports: [AgendaModule],
controllers: [AppController],
providers: [AppTasks],
})
export class AppModule implements OnModuleInit {
constructor(
private readonly moduleRef: ModuleRef,
private readonly taskRegister: AgendaTaskRegisterService,
) {}
async onModuleInit() {
this.taskRegister.setModuleRef(this.moduleRef);await this.taskRegister.register(AppTasks, {
collection: 'test',
options: {
db: {
address: 'mongodb://127.0.0.1/agenda',
options: {
useNewUrlParser: true,
},
},
},
});
}
}
```