npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@coya/task-manager

v0.2.2

Published

Scheduler for run tasks successively or simultaneously

Downloads

20

Readme

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.

Parameter | Type | Description | Default value -------- | --- | --- | --- taskList | array | list of objects implementing or inheriting the Task class | none

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.

Parameter | Type | Description | Default value -------- | --- | --- | --- taskList | array | list of objects implementing or inheriting the Task class | none

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)