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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tsdiapi/cron

v0.2.1

Published

A powerful cron scheduling plugin for the TSDIAPI-Server framework, enabling declarative and dynamic task management.

Downloads

162

Readme

Cron Scheduler Plugin for TSDIAPI-Server

TSDIAPI-Cron is a plugin for the TSDIAPI-Server framework, designed to simplify scheduling and managing cron jobs in TypeScript projects. It integrates seamlessly with the framework and utilizes node-cron for precise task scheduling.

Features

  • Declarative Cron Task Definition: Define cron tasks using a decorator (@CronTask).
  • Manual Cron Task Registration: Dynamically register cron tasks at runtime.
  • Integration with TSDIAPI-Server: Automatically initialize and manage tasks within the framework's lifecycle.
  • Customizable Options: Add metadata like names and descriptions for better task management.
  • Scalable Architecture: Easily handle both predefined and dynamic cron jobs.

Installation

npm install @tsdiapi/cron

or use @tsdiapi/cli to add it to your project:

tsdiapi plugins add cron

Code Generation

| Name | Description | | ------ | ----------------------------------------------- | | base | Create a new cron job with a predefined schedule. |

The TSDIAPI-Cron plugin includes a generator to streamline cron job creation. Use the tsdiapi CLI command to generate cron job files automatically:

tsdiapi generate cron

This command will create a new cron job with the necessary structure, including decorators and scheduling logic. You can specify the schedule and customize the task logic according to your needs.

Getting Started

Define a Cron Task

Use the @CronTask decorator to define a cron job:

import { CronTask } from "@tsdiapi/cron";
import { Service } from "typedi";

@Service()
export class TestCron {
  @CronTask("*/5 * * * * *", {
    name: "testTask",
    description: "Test cron task",
  }) // Every 5 seconds
  async testTask() {
    console.log("Executing test cron task");
  }
}

Register the Plugin

Add the plugin to the createApp function of your TSDIAPI-Server application:

import { createApp } from "@tsdiapi/server";
import CronPlugin from "@tsdiapi/cron";

createApp({
  plugins: [new CronPlugin()],
});

Configuration Options

The plugin supports the following configuration options:

PluginOptions

| Option | Type | Default Value | Description | | ------------------ | -------- | ------------------- | ------------------------------------- | | autoloadGlobPath | string | "*.cron{.ts,.js}" | Glob pattern to find cron task files. |

Example usage:

import CronPlugin from "@tsdiapi/cron";

createApp({
  plugins: [
    new CronPlugin({
      autoloadGlobPath: "*.cron.ts", // Custom glob pattern
    }),
  ],
});

Plugin Lifecycle Integration

TSDIAPI-Cron hooks into the plugin lifecycle to ensure tasks are started and managed efficiently:

  • onInit: Initializes the plugin and loads cron tasks.
  • afterStart: Automatically schedules all defined tasks.
  • beforeStart: Custom pre-start logic can be added here if necessary.

Logs and Debugging

TSDIAPI-Cron logs information about scheduled tasks, including their names and schedules. Ensure your application's logger is properly configured to capture these messages for debugging purposes.


Contributing

Contributions are welcome! Feel free to open issues or submit pull requests to improve the plugin.


License

This library is licensed under the MIT License. See the LICENSE file for details.

This documentation provides an overview of the library, how to set it up, and detailed examples for integration and usage. Let me know if you'd like to refine it further!