vinks / nest-agenda-jobs

Agenda task wrapper module for Nestjs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Please provide examples for periodic tasks and schedules

ZuSe opened this issue · comments

@vinks

First of all thanks for your wrapper.
We started today integrating agenda into our nestjs project. It really makes life easier.
Nevertheless we are stucked on how to trigger scheduled tasks with it.

Our code looks like this:

const job = await this.agendaService.createJob(this.myTask, {
          type: () =>  new Date(task.dueDate.setMinutes(task.dueDate.getMinutes() - DELAY_DEFAULT_REMINDER)),
          autoRemove: true,
        }, task);

we also tried with providing an iso-date-string to type and a Date Object.
The task creation fails with

(node:25958) UnhandledPromiseRejectionWarning: TypeError: job[jobParams.type] is not a function
[0] at AgendaService. (/home/ppalacin/Development/Repositories/dc-insuite-sol-iatros-gateway/src/node_modules/nest-agenda-jobs/dist/agenda.service.js:61:36)
[0] at Generator.next ()
[0] at /home/ppalacin/Development/Repositories/dc-insuite-sol-iatros-gateway/src/node_modules/nest-agenda-jobs/dist/agenda.service.js:14:71
[0] at new Promise ()

I hope you can help us with that as the docs don't point out how to specify periodic tasks or future schedules.

For anybody looking for the solution.


 const job = await this.agendaService.createJob(this.myTask, {
          type: 'schedule',
          time: jobTime,
          autoRemove: true,
        }, task._id);