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

@pyramid-drama/nestjs-cron

v0.2.3

Published

NestJS CRON module that allows you to easily setup CRON for your controllers or services

Downloads

4

Readme

alt cover

Fork from this repository

npm version npm version

NestJS cron package allows you easily setup cron for your controllers or services.

npm i @pyramid-drama/nestjs-cron

To use cron, decorate your class with @Scheduled() and method with @Cron(). Your class has to be a provider or a controller that is declared in any module.

import { Cron, Scheduled } from 'nestjs-cron';

@Injectable()
@Scheduled()
export class MyClass {
	@Cron('* * * * * *')
	async myMethod() {
		//...
	}
}

'* * * * * *' - is a standart cron notation. In this example it will be triggered every second. Additionaly you can use options:

@Cron('* * * * * *', {
	delay: 10000,
	launchOnInit: true,
	sync: true,
})
async myMethod() {
	//...
}
  • delay - Launch job after a specified time (in milliseconds)
  • launchOnInit - Launch job one time right after start
  • sync - Wait for method to finish before launching next tick if your function takes more time than cron.

Cron Intercepter

To intercept cron you can use @CronIntercepter decorator. You pass class that implements CronIntercepterClass as a parameter. It has one intercept method that returns Promise<boolean>.

export class MyIntercepter implements CronIntercepterClass {
	async intercept() {
		return false;
	}
}

Usage example:

@Scheduled()
@Injectable()
export class AppService {
	@CronIntercepter(MyIntercepter)
	@Cron('* * * * * *')
	getHello() {
		console.log('test');
	}
}

If intercept method returns true your cron will run as planned. If false method run will be skipped.