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

redibox-hook-schedule

v2.0.1

Published

Advanced redibox powered scheduling

Downloads

14

Readme

dependencies build Coverage Status npm version License

RediBox Schedule

Allows functions to run at set times, taking into consideration multi-server environments for hassle free scheduling.

Works well with Jobs.

Installation

First ensure you have RediBox installed.

Install Schedule via npm:

npm install redibox-hook-schedule --save

Usage

Configure schedules

Within your redibox config, we'll setup a new schedule object containing a schedules array. Each array item consists of a runs function, data and an interval.

  • runs [Function/String] A function or string (a globally available function as a dot notated string i.e. some.fooBar function which would resolve to global.some.fooBar automatically).

  • data [Array/Object/Primitive] Any data to pass along to each schedule function.

  • interval [String] A string of the interval time, compatible with Later.js.

  • multi [Boolean]

    • default: false If true, the schedule will run on every server. If false it'll be locked to a single server only.
{
  schedule: {
    schedules: [
      runs: function(schedule) {
        // do something every 5 minutes
        console.log('The value of foo is: ' + schedule.data.foo);
      },
      data: {
        foo: 'bar',
      },
      interval: 'every 5 minutes',
    ],
  },
}

Accessing schedule data

If passing in a function directly (like above), the schedule is available to the runs function as the first argument, where the data can be accessed via schedule.data.

Schedule Timing

Under the hood, the schedule uses Later. If a schedule is set to run every 1 minute, it will run on the minute, every minute. This ensures uniform schedules across multiple environments. It does not run 1 minute after the server booted.

Multi-server environments

Typically a large application will deploy many servers running the same code base. As expected the schedule will run on each individual server. If you have 20 servers deployed, and a schedule runs every minute to query an external API then update your database, you don't want 20 servers doing this at once.

Luckily, by default only a single server can only run a schedule at any one time. This is handled by utilising Redis locks. Once a schedule is picked up by a server, it is locked on Redis and cannot be run again until it is unlocked (which is performed automatically).

There might be however use cases where running a scheduled task across all servers is required. In this case, simply set the multi option to true on the schedule object.

License

MIT