A package to manage cron-jobs in a node.js Typescript application.

Overview

@ose4g/cron-manager

npm (scoped) npm npms.io (final) npms.io (final) Libraries.io dependency status for latest release, scoped npm package

This package is a package to manage cron-jobs in a node.js Typescript application. It is built using node-cron and reflect-metadata packages

Installation

npm i @ose4g/cron-manager

Usage

The package works with decorators and hance the following lines should be in your tsconfig.json file

"experimentalDecorators": true,
"emitDecoratorMetadata": true,

Annotate your Job class with @cronGroup and annotate each handler with @cronJob

import { cronGroup, cronJob, CronManager } from "@ose4g/cron-manager";


@cronGroup('jobs')
class JobService{
    constructor(private name:string){}

    @cronJob('*/1 * * * * *','print_name_func')
    printName(){
        console.log(this.name)
    }
}

@cronGroup('auth')
class AuthService{
    constructor(private users: any[]){}

    @cronJob('* * * * * *','my_unban_func')
    unbanUser(){
        console.log(`There are ${this.users.length} users in the application`)
    }
}
const manager = new CronManager();

const jobService = new JobService('Ose4g');
const authJob = new AuthService([])

manager.register(JobService, jobService)
manager.register(AuthService,authJob)


manager.startAll() //starts all jobs
manager.stopAll() //stops all jobs

//starting and stopping for specific groups
manager.startGroup('jobs') //starts only jobs in the class with tag equal to jobs
manager.stopGroup('jobs') //stops only jobs in the class with grouptag equal to jobs

//starting and stopping for specific handlers or jobs
manager.startHandler('my_unban_func') //starts the single job with tag equal to my_unban_func
manager.stopHandler('my_unban_func') //stop the single job with tag equal to my_unban_func

manager.getGroups() // returns ['auth','jobs']
manager.getHandlers() //returns ['my_unban_func','print_name_func']

Methods

  • @cronGroup( groupTag? : string )
    params
    • groupTag: tag to uniquely identify a a set of jobs. The same groupTag can be used for multiple classes.

  • @cronJob( cronExpression: string, handlerTag?: string)
    params
    • cronExpression: Expression describing the cron interval. The package uses node-cron in the background and hence the expression description is the same.
    • handlerTag: unique string to identify a single job. The job can be started and stopped using that tag.

  • manager.register(Class:Function, instance: any)
    It registers an instance of a class to the cron job manager.
    params
    • Class: The class we're registering
    • instance: An instance of that class
You might also like...

An application that allow users to manage their daily task.

An application that allow users to manage their daily task.

An application that allow users to manage their daily task. They can add and delete a specific task, and even delete all those which already completed buiilt with JavaScript, webpack and experiments with Jest as a unit testing framework

May 16, 2022

Web Application for admin of T-quest game to manage presets of questions

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Jun 30, 2022

LiveTabs is a Javascript library that allows you to create and manage tabs on the fly. This library gives the ability to your application to act like browser tabs, making dynamic tabs.

LiveTabs Table of content Description Goals Technologies Setup Description LiveTabs is a Javascript library that allows you to create and manage tabs

May 3, 2022

A sample Node.js application that uses the database-js package.

database-js-starter A sample Node.js Express API built using the PlanetScale serverless driver for JavaScript. It contains sample API endpoints that c

Dec 19, 2022

This package is for developers to be able to easily integrate bad word checking into their projects.\r This package can return bad words in array or regular expression (regex) form.

Vietnamese Bad Words This package is for developers to be able to easily integrate bad word checking into their projects. This package can return bad

Nov 3, 2022

An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

Dec 28, 2022

Template TypeScript Node.js package with all the CI bells & whistles I commonly use. ✨

Template TypeScript Node.js package with all the CI bells & whistles I commonly use. ✨

Template TypeScript Node Package Template TypeScript Node.js package with all the CI bells & whistles I commonly use. ✨ Usage npm i template-typescrip

Jan 2, 2023

Node js package makes creating node jd dependincies files like Controllers,Entities and Repositories easier by executing a few instructions

Node js package makes creating node jd dependincies files like Controllers,Entities and Repositories easier by executing a few instructions

Nodejs Studio Node js package makes creating node js project dependincies files like Controllers,Entities and Repositories easier by executing a few i

Oct 12, 2022

This is an application that entered the market with a mobile application in real life. We wrote the backend side with node.js and the mobile side with flutter.

HAUSE TAXI API Get Started Must be installed on your computer Git Node Firebase Database Config You should read this easy documentation Firebase-Fires

Nov 4, 2021
Releases(v1.3.1)
  • v1.3.1(Apr 7, 2022)

    Adds two new methods

    • manager.getGroups(): returns a list containing all group names in the project
    • manager.getHandlers(): returns a list containing all handler tags in the project
    Source code(tar.gz)
    Source code(zip)
Owner
Osemudiamen Itua
I am a backend developer and aspiring DevOps Engineer. I'm open to opportunities to learn and apply skills to solve problems.
Osemudiamen Itua
App to manage maintenance calls. App to manage maintenance calls. This application was created for the purpose of studies.

App to manage maintenance calls. App to manage maintenance calls. This application was created for the purpose of studies.

Rodrigo Gonçalves 112 Dec 26, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
This app helps manage a bookstore. It comes in handy when you need to manage a personal book store or library. Entirely built on es6.

Awesome Books A Microverse project on learnong javascript. Additional description about the project and its features. Built With HTML5 CSS3 Javascript

Atugonza ( Billions ) Joel 13 Apr 22, 2022
This repository contains a basic example on how to set up and run test automation jobs with CircleCI and report results to Testmo.

CircleCI test automation example This repository contains a basic example on how to set up and run test automation jobs with CircleCI and report resul

Testmo 2 Dec 23, 2021
CLI Progress Bar implemented in NodeJS to track Time, ETA and Steps for any long running jobs in any loops in JS, NodeJS code

NodeJS-ProgressBar CLI Progress Bar for NodeJS and JavaScript to track Time, ETA and Steps for any long running jobs in any loops in JS, NodeJS code D

Atanu Sarkar 5 Nov 14, 2022
Help Ukrainian people find jobs in the EU, navigate visas and translating CVs.

We invite Ukrainians to Europe Since the beginning of war in Ukraine, more than 3.7 million people have left Ukraine, while an estimated seven (7) mil

Dejan Jacimovic 14 Nov 12, 2022
A simple Prometheus (aggregated) push gateway allowing stateless/serverless workloads, ephemeral and batch jobs to easily expose their metrics.

Serverless Prometheus (aggregated) Push Gateway A simple Prometheus (aggregated) push gateway allowing stateless/serverless workloads, ephemeral and b

Adam Janiš 17 Dec 4, 2022
A portal for finding and posting jobs. Assignment for internship.

Naukri Dundho A portal for finding and posting jobs. Assignment for internship. ?? Explore the docs » • Report Bug • Request Feature • Backend Documan

Prasoon Soni 5 Sep 14, 2022
A flexible gateway for running ML inference jobs through cloud providers or your own GPU. Powered by Replicate and Cloudflare Workers.

Cogflare (Working title) Cogflare is a Cloudflare Workers application that aims to simplify running distributed ML inference jobs through a central AP

NightmareBot 14 Dec 12, 2022
Multi-platform node package bundle to a package.json.

dmpc Multi-platform node package bundle to a package.json. install ### npm mode npm i -g @kingsword/dmpc ### yarn mode yarn global add @kingsword/dmp

Kingsword 2 Oct 16, 2022