npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pulsecron/nestjs-pulse

v1.0.7

Published

The modern MongoDB-powered scheduling library pulse for NestJS

Downloads

598

Readme

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:

  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!

License

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