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

arc-scheduler

v2.0.0

Published

A thin task scheduler, for easily managing recurrent or single fire tasks.

Downloads

4,063

Readme

arc-scheduler

A functional scheduler that enables easy functional task bindings.

Install & Testing

$ npm install arc-scheduler --save
$ npm run test

Features

  • A clock to easily listen for events to schedule jobs around (ie. NEW_DAY or NEW_WEEK)
  • A task system to easily schedule recurrent tasks and specific times (ie. First Monday, 12:00pm of the month)
  • A task queue to make unpredictable states less catastrophic (ie. limit jobs in queue, prevent duplicate jobs from being added to queue)
  • Supports task persistence (ie. if your service fails, rehydrate tasks with data to ensure they continue to behave as expected)
  • A full simulation mode to enable testing real world behavior over time

Basic Events Usage

const ArcScheduler = require('arc-scheduler');

//Create a new scheduler
const TestScheduler = new ArcScheduler();

TestScheduler.on(ArcScheduler.EVENT_NEW_DAY, ()=>{
    //Do things when it's a new day!
})

//Start the scheduler
TestScheduler.startRealTime();

Basic Tasks Usage

const ArcScheduler = require('arc-scheduler');

//Create a new scheduler
const TestScheduler = new ArcScheduler();

//Get a new task
const TestTask = TestScheduler.getNewTask('testTask1');

//Set the job to actually run
TestTask.setJob(async (_ArcDate) => {
    //Do something
});

//Fire immediately, and then fire every five minutes in perpetuity
TestTask.setFireOnStart(true).setRepeatInterval(0, 5)

//Schedule it
TestScheduler.scheduleTask(TestTask);

//Start the scheduler
TestScheduler.startRealTime();

API

TODO: Fill in the API. For now refer to the healthyScheduler.js in the _tests_ folder to see usage patterns. Refer to the unhealthyScheduler.js in the _tests_ folder to see queueDepth management.

NOTES:

This system has two primary concepts. Exclusion filters (ie. check for configurations set, and identify when NOT to run), and then a repeat interval (ie. after a job CAN run, identify an interval before it can run again). By default the repeatInterval value is set to one day. In effect, when you consider the following:

    //Set days of week, time of day
    TestTask.setDaysOfWeek(0,1,1).setTimeOfDay(8,9);

Every day the scheduler will check to see if it meets the exclusion criteria (is it Monday/Tuesday?). Assuming it's Monday, it will fire the job, and then use the repeatInterval to identify the minimum delay before the job can fire again. By default 24 hours later.

This keeps things relatively simple, regarding the flexibility of timing of when a job can fire based on cirucmstances (ie. if a queue is full, or a previous job is blocking, the job is comfortable at firing as close to 8:09 as possible, which may in fact be... 8:30). It can however introduce some unexpected behaviors.

For example, if you schedule a job to happen at the last second of the day (23:59:59) and it misses that window, it may now meet the exclusion criteria of the next day and not fire at all. Or, if you reduce the repeat interval to say 6 hours, and a job starts firing at 8:00, it would also fire at 14:00 and 20:00.

Or, if you try to set the repeatInterval to say one week, after it fires the first job, even if you have it set to fire on different days of the week, it will wait a week before being eligible again.

There are ways around this, and I might eventually get annoyed and rework this approach, but for now the simplicity of the API, with consistent behavior seemed to do the trick.