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

sfn-scheduler

v0.1.1

Published

Simple Friendly Node.js Scheduler for tasks.

Downloads

5

Readme

SFN-Scheduler

Simple Friendly Node.js Scheduler for tasks.

Install

npm i sfn-scheduler

Example

const { Schedule } = require("sfn-scheduler");

// the schedule will run automatically after you've instantiated the class

var schedule1 = new Schedule("every 2 seconds", () => {
    console.log("This schedule runs every 2 seconds.");
});

var schedule2 = new Schedule("in 2 days", () => {
    console.log("This schedule has been waiting for 2 days.");
});

var schedule3 = new Schedule("20:00", () => {
    console.log("This schedule runs at 20:00 this evening.");
});

var schedule4 = new Schedule("*:30", () => {
    console.log("This schedule runs at 30 minutes of every hour in today.");
});

var schedule5 = new Schedule("*-*-1 8:00", () => {
    console.log("This schedule runs on every first day in every month.");
});

Schedule pattern

Here I will list several patterns (statements), just to demonstrate the capability of this package, they're all in human language.

  • runs the schedule every 2 hours
  • I wish to run the program in 2 hours
  • execute the application on Monday
  • runs at 20:00 today
  • runs in 2 days
  • runs every day at 12:00
  • only runs on Monday in this month
  • 2018-8-* 12:00
  • runs in Aug. 2018, every day at 12:00

This module is backed by sfn-schedule-parser, which exposes a common API for Node.js to build schedulers. For full supported patterns, you should follow it for newest features.

Return values from the task

If you return a value from the task function, unlike most of other timer modules, the returning value in a task function of this module will not be ignored, and it will be used as an argument passed to the task function again at the next tick. See this example:

var schedule = new Schedule("runs every 2 minutes", (num = 1) => {
    console.log("Running count: %d.", num);
    return num + 1;
});

// The output would like this:
// Running count: 1.
// Running count: 2.
// Running count: 3.
// ...

How to stop?

You can call the method stop() to terminate the schedule whenever you want.

var schedule = new Schedule("runs every 2 minutes", () => {
    // ...
    schedule.stop();
});

Once you have stopped the schedule, you can call method resume() to restart it.