datetime-scheduler

1.0.3 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i datetime-scheduler

Weekly Downloads

1

Version

1.0.3

License

MIT License

Unpacked Size

8.84 kB

Total Files

5

Last publish

Collaborators

  • lubino