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

tasking-pm

v1.0.3

Published

Tasking Process Manager is a module that helps with spreading a workload over different processes

Downloads

9

Readme

TaskingPM

A NodeJS process manager module that uses a queue of tasks to execute functions in paralel

https://github.com/ccezarst/TaskingPM

How to use

To use you need to import the package by using

const taskingPM = require("taskingPM")

After, you can create a new task using

taskingPM.newTask(currentWorkingDirectory, taskFunction, taskArguments, callback)
  • currentWorkingDirectory: specified in which directory the processes will be started in, so you can import local files inside the task
  • taskFunction: the function that is going to be ran in paralel
  • taskArguments: parameters that you can pass to the taskFunction to make your life easier
  • callback: after the taskFunction is done and it returns it's result, this callback function is called with the parameter being the result

Working example

const customLogger = {
    warn: function (text) {
        console.log(text)
    },
    info: function (text) {
        console.log(text)
    },
    error: function (text) {
        console.log(text)
    }
}
const taskingPM = new require("./index")
let tasks = 50
taskingPM.setLogger(customLogger)
let i = 1
let interval = setInterval(function () { 
    taskingPM.newTask(process.cwd(), (extra) => {
        return "Hello world! " + extra["count"]
    }, { count: i }, (result) => { console.log(result) })
    i += 1;
    if (i >= tasks) {
        clearInterval(interval)
    }
}, 100)

After waiting one second, the code creates 50 tasks. You will see when a task is finished in the console as it prints "Hello world! {taskNumber}"

Extra functions

setLogger

setLogger(logger)

By default the package doesn't output any logs. Set a custom logger. The logger must include info, error and warn functions that take a single text parameter.

setConfigs

setConfigs(maxIdleTime, maxProcesses) {},

Set configs. maxIdleTime = the maximum amount of time(in ms) a process can be idle before it is killed. Longer times mean that sporatic(chaotic) creation of tasks are handler better but the processes remain open draining a bit of resources. maxProcesses = the maximum amount of processes the package can generate

deleteTask

deleteTask(task)

Deletes a task from the queue so it doesn't execute. task = the tasks object(is returned from newTask)

flushTasks

flushTasks()

Delete all tasks from the queue

closeAllProcceses

closeAllProcesses()

Close all active processes

getTasks

getTasks()

Returns all of the tasks in the queue in the order they are going to be executed.

getActiveProcesses

getActiveProcesses()

Returns all open/active processes. The processes come in a CustomChildProcess object from where you can access information such as if the process is idle.

exit

exit()

For exiting gracefully. Deletes all tasks and closes all processes

class CustomChildProcess {
  proc: handle to the nodejs child process
  id: internal process ID
  spawned: if the nodejs child process has spawned yet
  working: true when it's working on a task, false when idle
  finishedWorkingAtEpoch: when a process finishes working, it marks the date in this variable using Date.now()
  execTask(task): executes a task. It is recommended that you don't execute tasks manually :/
  kill: kills the nodejs child process
}