Socket
Socket
Sign inDemoInstall

bella-scheduler

Package Overview
Dependencies
1
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bella-scheduler

To do something later, repeater


Version published
Weekly downloads
27
decreased by-77.12%
Maintainers
1
Install size
148 kB
Created
Weekly downloads
 

Readme

Source

bella-scheduler

Lightweight util for handling schedule in your Node.js and browser apps.

NPM Build Status codecov Dependency Status NSP Status

Setup

  • Node.js

    npm install bella-scheduler
    
  • CDN

  • Also supports ES6 Module, CommonJS, AMD and UMD style.

Usage

import {
  once,
  every,
  daily
} from 'bella-scheduler';

once('5s', () => {
  console.log('Resolved task.');
});

every('sunday 8:00', () => {
  console.log('Resolved a task on Sunday at 8 AM.');
});

daily('15:00', () => {
  console.log('Resolved a daily task at 3 PM...');
});

APIs

  • .every(String pattern, Function callback)
  • .once(String pattern, Function callback)
  • .hourly(String pattern, Function callback)
  • .daily(String pattern, Function callback)
  • .monthly(String pattern, Function callback)
  • .yearly(String pattern, Function callback)
  • .unregister(String taskId)

Almost cases you can use this library instead of setInterval or setTimeout, because it runs only one timer for the entire process. Regarding parameter "pattern" for .every(), it may be:

1, A string in the format of 'Y m d h i s'.

For example:

- .every('2040 05 16 15 30 10', callback);
   --> run callback at 15:30:10 on May 16, 2040
- .every('* 05 16 15 30 10', callback);
   --> run callback at 15:30:10 on May 16 of years
   --> similar to yearly('05 16 15 30 10', callback)
- .every('* * 16 15 30 10', callback);
   --> run callback at 15:30:10 on the 16th of months
   --> similar to monthly('16 15 30 10', callback)
- .every('* * * 15 30 10', callback);
   --> run callback at 15:30:10 of days
   --> similar to daily('15 30 10', callback)
- .every('* * * * 30 10', callback);
   --> run callback at the 10th second of the 30th minute of hours
   --> similar to hourly('30 10', callback)
- .every('* * * * * 10', callback);
   --> run callback at the 10th second of minutes.

2, A string in the format of 'weekday H:i:s'.

For example:

- .every('sunday 15:30:10', callback);
   --> run callback on Sundays at 15:30:10
- .every('sunday 15:30', callback);
   --> run callback on Sundays at 15:30:00
- .every('sunday 15', callback);
   --> run callback on Sundays at 15:00:00

It's possible to use "sun" instead of "sunday", "mon" for "monday", and so on.

3, A string in the format of 'N unit'.

For example:

- .every('5m', callback)
   --> call callback every 5 minutes
- .once('5m', callback)
   --> call callback in 5 minutes, then stop

The available units: d (days), h (hours), m (minutes), s (seconds).

The method .once() do the same thing as .every(), but just once. The 4 remain methods yearly(), monthly(), daily(), hourly() can be looked as the shortcuts of every().

.unregister(taskId)

Remove a task from scheduler.

Returns true if successfull removing.

let taskId = scheduler.every('5m', callback);
scheduler.unregister(taskId);

Test

git clone https://github.com/ndaidong/bella-scheduler.git
cd bella-scheduler
npm install
npm test

License

The MIT License (MIT)

Keywords

FAQs

Last updated on 07 Aug 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc