Skip to content

JavaScript (ES6) module for executing scheduled tasks

License

Notifications You must be signed in to change notification settings

lubino/datetime-scheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

datetime-scheduler

ECMAScript 6 (JavaScript) NPM module for executing scheduled tasks

Installation

npm i datetime-scheduler --save

Notice: This module has zero NPM dependencies, but it uses ES6 language.

Usage

This example calls asyncTask method every saturday and sunday at 12:15 (and 30.500 seconds)

const {createScheduler} = require('datetime-scheduler');

const configuration = {
    "days": {
        "sunday":    true,
        "monday":    false,
        "tuesday":   false,
        "wednesday": false,
        "thursday":  false,
        "friday":    false,
        "saturday":  true
    },
    "time": {
        "hours": 12,
        "minutes":15,
        "seconds": 30,
        "millis": 500
    }
};

const options = {
    asyncTask: async () => {
        console.log("Doing staff");
        await new Promise(resolve => setTimeout(resolve, 10000));
        console.log("Finishing staff");
    }
};

createScheduler("weekend at 12:15:30.500", configuration, options);

In case you need only one execution on a specific day

const specificDay = "2019-05-18T19:30:00.000Z";
const configuration = {
    "timestamp": new Date(specificDay).getTime()
};

You also can use a timestamp or an interval as your configuration options. Interval should be stated in minutes.

const configuration = {
    "interval": 40
};

Check weekend.js for a working example.

License

MIT License

About

JavaScript (ES6) module for executing scheduled tasks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published