0.0.5 • Published 6 years ago

constraint-schedulr v0.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

schedulr

Constraint based cron-like scheduler.

Summary

Goal for MVP

const s = require("schedulr");

// Runs function every 8 hours (start time is now, so, current time - time of beggining % 8h == 0) if day is monday. 
s.run().every(8).hours().fromNow().if({day: "monday"}).function(() => {});

// Runs function every 8 hours (start time is today, so, current time - day of the beggining % 8h == 0) if day is monday. 
s.run().every(8).hours().fromStartOfDay().if({day: "monday"}).function(() => {});

// Runs on *:00:00 if it is third week of month. 
s.run().on().hour().if({week: 3}).function(() => {});

// Runs 8 times each hour if week is 3th. 
s.run(8).times().in().hour().if({week: 3}).function(() => {});

Documentation

Installation

npm install constraint-schedulr

What is not ready yet?

  • if function

  • month and year interval

Using chaining for configuration

Since most of cron-like schedulers are hard to learn for people who are just starting, I decided to make my very easy for humans to read and also made it so users can do a lot more customization that way.

schedulr run(int)

run takes as param the number of times you want to run function in certain interval. default is 1

schedulr times(), schedulr in()

These functions are there just to make chain mora human readable.

schedulr every()

Sets multiplier for time interval.

These functions are there just to make chain mora human readable.

schedulr years(), schedulr months(), schedulr weeks(), schedulr days(), schedulr hours(), schedulr minutes(), schedulr seconds()

These functions add constraint so function runs every x * time interval, based on value set using schedulr every(int)

These functions are there just to make chain mora human readable.

schedulr fromNow(), schedulr fromStartOfDay()

These 2 functions set reference point for constraint solver to calculate intervals against. Default value is now.

schedult if(array)

This function takes array of constraints and adds them to constraints array.

schedulr function(function)

This function adds function to list of functions to be called when constraints added so far got resolved.

schedulr and(int)

This function starts new constraint and uses the same arguments as run.

Authors

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago