Coder Social home page Coder Social logo

pulsecron / nestjs-pulse Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 177 KB

The modern MongoDB-powered scheduling library pulse for NestJS

Home Page: https://pulsecron.com

License: MIT License

TypeScript 100.00%
nestjs cron task-scheduler mongodb typescript job scheduler scheduling agenda cronjob mongodb-scheduler bull bee nestjs-scheduler

nestjs-pulse's Introduction

project-logo

Nestjs-PULSE

The modern MongoDB-powered scheduling library for NestJS

license last-commit repo-top-language repo-language-count


Table of Contents

Overview

Pulse module for NestJS




Getting Started

Installation

$ npm install --save @pulsecron/nestjs-pulse @pulsecron/pulse

Example

app.module.ts
// src/app.module.ts

import { Module } from '@nestjs/common';
import { PulseModule } from '@pulsecron/nestjs-pulse';
import { NotificationsModule } from './notification/notification.module';

@Module({
  imports: [
    PulseModule.forRoot({
      db: {
        address: 'mongodb://localhost:27017/pulse',
      },
    }),
    NotificationsModule,
  ],
  providers: [],
})
export class AppModule {}
notification.module.ts
// src/notification/notification.module.ts

import { Module } from '@nestjs/common';
import { PulseModule } from '@pulsecron/nestjs-pulse';
import { NotificationsQueue } from './notification.processor';

@Module({
  imports: [
    PulseModule.registerQueue('notifications', {
      processEvery: '1 minutes',
      autoStart: false, // default: true
    }),
  ],
  providers: [NotificationsQueue],
  exports: [],
})
export class NotificationsModule {}
notification.processor.ts
// src/notification/notification.processor.ts

import { Job } from '@pulsecron/nestjs-pulse';
import { Every, Queue, Define, Schedule } from '@pulsecron/nestjs-pulse';

@Queue('notifications')
export class NotificationsQueue {
  @Every({ name: 'send notifications', interval: '1 minutes' })
  async sendNotifications(job: Job) {
    console.log('Sending notifications[1]');
  }

  @Schedule({ name: 'send notifications', when: 'tomorrow at noon' })
  async sendNotifications(job: Job) {
    console.log('Sending notifications[2]');
  }

  @Now()
  async sendNotifications(job: Job) {
    console.log('Sending notifications[3]');
  }
   
  @Define({ name: 'emailJob' })
  async test(job: Job) {
    console.log('Sending email to:', job.data.to);
  }
}

notification.service.ts
import { Injectable } from '@nestjs/common';
import { Inject } from '@nestjs/common';

@Injectable()
export class NotificationService {
  constructor(@Inject('notifications') private pulse: Pulse) {}

  async scheduleEmail(email: string) {
    const emailJob = this.pulse.create('emailJob', { to: email });
    emailJob.unique(
      {
        'data.to': email,
      },
      {
        insertOnly: true,
      }
    );
    emailJob.schedule('5 seconds').save();
  }
}



Contributing

Contributions are welcome! Here are several ways you can contribute:

Contributing Guidelines
  1. Fork the Repository: Start by forking the project repository to your github account.
  2. Clone Locally: Clone the forked repository to your local machine using a git client.
    git clone https://github.com/pulsecron/nestjs-pulse
  3. Create a New Branch: Always work on a new branch, giving it a descriptive name.
    git checkout -b new-feature-x
  4. Make Your Changes: Develop and test your changes locally.
  5. Commit Your Changes: Commit with a clear message describing your updates.
    git commit -m 'Implemented new feature x.'
  6. Push to github: Push the changes to your forked repository.
    git push origin new-feature-x
  7. Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
  8. Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
Contributor Graph




License

This project is protected under the MIT License. For more details, refer to the LICENSE file.




nestjs-pulse's People

Contributors

code-xhyun avatar semantic-release-bot avatar

Stargazers

 avatar cheeselemon avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.