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

@judeoscar/job-scheduler

v1.0.2

Published

A simple package that helps schedule and perform tasks.

Downloads

184

Readme

Job Scheduler

A lightweight Node.js job scheduling package to create, run, and manage recurring jobs using intervals. It allows you to schedule tasks, track their statuses, and stop them as needed, all while maintaining state with persistent storage.

Features

  • Schedule tasks with specific intervals
  • Persist job state to a JSON file
  • Restore jobs upon initialization
  • Start, stop, and manage job intervals easily

Installation

npm install @judeoscar/job-scheduler

Usage

Basic Setup

const Scheduler = require("job-scheduler");

// Initialize scheduler instance
const scheduler = new Scheduler();

// Schedule a new job
scheduler.scheduleJob("greet", 5000, () => console.log("Hello, world!"));

// Run a specific job
scheduler.runJob("greet");

// Stop a running job
scheduler.stopJob("greet");

// Delete a specific job
scheduler.deleteJob("greet");

Scheduling a Job

To schedule a job, use the scheduleJob method. Specify a name, interval in milliseconds, and the task (a function) to execute.

scheduler.scheduleJob("jobName", interval, () => {
  console.log("Job is running...");
});

Running a Job

The runJob method allows you to run a specific job based on its name. Jobs will execute at the specified interval and will persist between sessions.

scheduler.runJob("jobName");

Stopping a Job

Use stopJob to stop a running job by name. This will clear the interval and update the job status in the persistent JSON file.

scheduler.stopJob("jobName");

Delete a scheduled job

The deleteJob method allows you remove a specific job from the json file based on the specified name.

scheduler.deleteJob("jobName");

API Reference

scheduleJob(name: string, interval: number, task: Function)

Schedules a new job.

  • name: The unique name of the job.
  • interval: The time in milliseconds between each execution of the task.
  • task: The function to be executed at each interval.

runJob(name: string)

Runs a job by name if it exists in the schedule.

  • name: The name of the job to run.

stopJob(name: string)

Stops a running job by clearing its interval and updating its status.

  • name: The name of the job to stop.

Persistent Storage

Jobs are saved in a JSON file (jobs.json) within the package directory, enabling job restoration upon re-initialization.

License

This project is licensed under the MIT License.