🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

nest-agenda-jobs

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nest-agenda-jobs

Bull tasks wrapper for NestJS framework

latest
Source
npmnpm
Version
0.2.3
Version published
Maintainers
1
Created
Source

Nest Logo

Description

This is a Agenda task wrapper module for Nest.

Installation

$ npm i --save nest-agenda-jobs

Quick Start

import { Injectable } from '@nestjs/common';
import { Task } from '../lib';

@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 '../lib';
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 '../lib';
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,
            },
          },
        },
      });
  }
}

FAQs

Package last updated on 18 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts