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

@gallolabs/scheduler

v0.1.2

Published

This is not a tasker.

Downloads

2

Readme

Scheduler

This is not a tasker.

"when" uses dates-iterators (see below)

// Simple Schedule

schedule({
    fn(infos) {
        console.log('Do job')
    },
    when: {
        times: ['PT2S'],
        limit: 5
    }
})

// Scheduler

const scheduler = new Scheduler({
    onError(error, id) {
        console.log('error on', id, error)
    }
})

scheduler.schedule({
    id: 'test1',
    fn() {
        console.log('Do job 1')
    },
    when: ['PT1S']
})

scheduler.start(abortSignal)

Dates Iterators

Various iterators to iterate over dates with various logics. Next method accepts date to jump to (only to the futur). prev() has been removed, only iterate to the futur is possible.

// The simplest

const iterator = new NativeDatesIterator({
    dates: [
        new Date('2023-09-01T19:00:00+02:00'),
        new Date('2023-08-15T00:00:00+02:00'),
        new Date('2023-09-15T12:00:00+02:00')
    ]
})

iterator.next() // {done: false, value: Date(2023-08-15T00:00:00+02:00)}
iterator.next(new Date('2023-09-05')) // {done: false, value: Date(2023-09-15T12:00:00+02:00)}
iterator.next() {done: true}

// Nexts are without call examples but still the same logic

new IntervalDatesIterator({
    interval: 1000 * 60 * 60 * 24, // Every milliseconds, like a setInterval
    roundInterval: true, // Optional
    startDate: new Date('2023-09-01T00:00:00+02:00'),
    endDate: new Date('2023-09-30T00:00:00+02:00'), // Optional
    limit: 10 // Optional
})

new IntervalDatesIterator({
    interval: 'P1M1W', // Every 1 Month, 1 Week. For example 2023-01-01T12:00:00 -> 2023-02-01T12:00:00 for P1M.
    // Same options than above
})

new IntervalDatesIterator({
    interval: { months: 1, weeks: 1 }, // equiv to above
    // Same options than above
})

new CronDatesIterator({
    cron: '0 17 */7 * *', // You know it. Last supplement is for seconds (optional)
    startDate: new Date('2023-09-01T00:00:00+02:00'),
    endDate: new Date('2023-09-30T00:00:00+02:00'), // Optional
    limit: 10 // Optional
})

new AggregateIterator({
    iterators: [
        new CronDatesIterator(...), // Example: each day
        new NativeDatesIterator(...),
        ...
    ],
    excludeIterators: [
        new NativeDatesIterator(...), // Example: except dates of Christmas
        ...
    ],
    limit: 10 // Optional
})

// You also can iterate with for or convert to Array, but take care to Infinity generations (each minute for example without limit nor endDate)

for (const date of new XxIterator(...)) {
    console.log(date)
}

// Bad idea without limit or endDate (except for NativeDatesIterator) or for big iterations (memory)
console.log(...new XxIterator(...))

// Factory : create from complex (or not) configurations without need of create yourself iterators
createIterator({
    times: ['0 4,8 * * *', 'P1D', new Date, 'P1M'],
    startDate: new Date('2023-11-05T00:00:00+01:00'),
    limit: 10000,
    excludedTimes: [new Date('2023-11-05T00:00:00+01:00')],
    roundInterval: true,
    endDate: new Date('2049-12-31')
})

The AggregateIterator allows you to iterate over dates mixing various logics, for example you want each day more specifics days. No limitations with the mix ...

Improvement ideas

  • Exclude periods ?
  • Aggregate consider double with arbitrary precision ?
  • Dynamic startDates / Dates to be able to have start date depending on the first next() call (NowIterator can be cool, but others have static startDate, so no coherent)