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

skedgy

v0.8.0

Published

Periodically check for and queue work to be done!

Downloads

34

Readme

skedgy

Periodically check for and queue work to be done!

Build Status Code Coverage Dependencies DevDependencies npm Monthly Downloads Total Downloads

Skedgy (pronounced "ske-gee") is an opinionated scheduling library for NodeJS. The purpose of skedgy is to periodically check for work with a random delay between each check, as well as queue and execute tasks with a random delay between each execution. The goal was to create a scheduler that acts naturally, not with exact timing that can be tracked. Tasks are always run one at a time and never retried.

Example:

import { Scheduler } from 'skedgy';

// Create a limited set of random 'response' data...
const responses = Array(10).fill(0).map((x) => Math.random().toString(36).substr(2, 10));

// Pretend this is a much cooler check...
async function someExternalRequest(): Promise<string> {
  await randomDelay(3000);
  return responses.pop();
}

// Pretend this is a much cooler action...
async function processData(text: string) {
  await randomDelay(3000);
  console.log(text.toUpperCase());
  await randomDelay(1000);
}

class ExampleScheduler extends Scheduler<string> {
  
  protected async poll(): Promise<void> {
    let result = await someExternalRequest();
    this.enqueue(result);
  }
  
  protected async work(item: string): Promise<void> {
    await processData(item);
  }
}

const sched = new ExampleScheduler({
  pollMinDelay: 3000,
  pollMaxDelay: 8000,
  taskMinDelay: 3000,
  taskMaxDelay: 5000
});

// Start the scheduler...
sched.start();

setTimeout(() => {
    // Force stop after 60s...
    sched.stop();
    process.exit(0);
}, 60 * 1000);

function randomDelay(delay: number) {
  return new Promise(resolve => setTimeout(resolve, Math.random() * delay));
}

Features:

  • Simple to use API.
  • Built on Promises!
  • Randomly vary the interval between polling.
  • Throttle the work functions with a random range (so it's not predictable).
  • Persists work to super simple, overridable queue (defaults to in-mem queue).

Contribute

  1. Fork it
  2. npm i
  3. npm run watch
  4. Make changes and write tests.
  5. Send pull request! :sunglasses:

License:

MIT