0.2.2 • Published 6 years ago

@coya/task-manager v0.2.2

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

Task Manager

Scheduler for run tasks successively or simultaneously.

Installation

npm install @coya/task-manager

Build (for dev)

git clone https://github.com/Cooya/TaskManager
cd TaskManager
npm install // it will also install the development dependencies
npm run build
npm run example // run the example script in "examples" folder

Usage examples

const { TaskManager, Task } = require('@coya/task-manager');

const firstTask = new Task('firstTask', 10, function() {
    console.log('hello');
    return Promise.resolve();
});

const secondTask = new Task('secondTask', 5, function() {
    console.log('hola');
    return Promise.resolve();
});

const thirdTask = new Task('thirdTask', 2, function() {
    console.log('failure');
    return Promise.reject();
});

const taskManager = new TaskManager();
taskManager.onTaskEnd(function(task) {
    console.log('The task "' + task.name + '" has been removed from the task manager.');
});
taskManager.onEnd(function() {
    console.log('All tasks have been stopped, task manager shutted down.');
});
taskManager.processAsynchronousTasks([firstTask, secondTask, thirdTask]);

Methods

processSynchronousTasks(taskList)

Process tasks list successively, it means that tasks are executed one by one. The following task is executed once the previous one is done.

ParameterTypeDescriptionDefault value
taskListarraylist of objects implementing or inheriting the Task classnone

processAsynchronousTasks(taskList)

Process tasks list simultaneously, it means that tasks are executed in the same time (using setTimeout()). It is different from setInterval() because the timer is launched after the task has been processed.

ParameterTypeDescriptionDefault value
taskListarraylist of objects implementing or inheriting the Task classnone

Task spec

The Task class, and so its constructor, contains three fields :

  • name => name of the task
  • timeInterval => interval in seconds between each task execution
  • maxFailuresInARow (optional) => determine the number of failures in a row before the task will be taken out of the task list (default it is 5)
  • run => task function called by the scheduler, it must return a promise (this function can be passed to the Task constructor or be a member method of the inheriting class)
0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.6

6 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago