vinks / nest-agenda-jobs

Agenda task wrapper module for Nestjs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

custom collection not working

KiariaQAQ opened this issue · comments

// App.tasks.ts

import { Injectable } from '@nestjs/common';
import { Task } from 'nest-agenda-jobs';
import * as Agenda from 'agenda';

@Injectable()
export class AppTasks {
  @Task({ name: 'justATest', collection: 'test' })
  async justATest(job: Agenda.Job, done: Function) {
    const result: number = (job.attrs.data || []).reduce((a, b) => a + b);

    setTimeout(() => {
      done(null, result);
  }, 900);
  }
}
// AppModule

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'
        }
      }
    })
  }
}

mogno