Class: TaskManager

taskManager~TaskManager(options)

new TaskManager(options)

Creat a new task manager normally you can use the default instance let taskManager = require('path/to/taskManager');
Parameters:
Name Type Description
options none yet or todo document
Properties:
Name Type Description
tasks Object key = task id , and val is the task object let task = { tid, // incrementing task id sh, // the comand executed options, // task options cb, // callback(task_id, data, isDone, isError) proc, // the instance of child_proccess time, // start time unix promise, // resolve(task) a promise which resolves when finished process 'close' event is fired status, // {name, val, msg, bg} for proggres bar, data, // buffer for task.proc.stdout. note this is a string vs proc.stdout is a stream setStatus() // function to set this tasks status todo read registerTask for anomaly's }
Source:

Members

simpleExec

NOT TRACKED BY TASK MANAGER spawn a child process easily
Source:

Methods

findTask(str) → {*}

search for a string in the sh command
Parameters:
Name Type Description
str
Source:
Returns:
Type
*

getStatus(nameopt) → {*|Object}

The official way of using taskManager.status
Parameters:
Name Type Attributes Description
name String <optional>
full status object if undefined otherwise just get the status of some particular thing/task.
Source:
Returns:
Type
* | Object

getTask(tid) → {*}

get task object by task id
Parameters:
Name Type Description
tid task id
Source:
Returns:
Type
*

promise(tid) → {*}

Return the promise for task completion
Parameters:
Name Type Description
tid
Source:
Returns:
Type
*

qStart()

Start the task q (sould be called when task is added to empty q)
Source:

qTask(opts, fn, …args)

Schedule a task to be completed in a friendly way aka one at a time in a nice orderly Q
Parameters:
Name Type Attributes Description
opts options
Properties
Name Type Description
eta an estimated time for the task to complete
priority -
cb called when the fn's promise resolves cb(qEntry, ...resolveArgs)
fn this function wll be called with your provided args when this task is started. "this" is set to the task object it MUST return a Promise or be an Object with property promise;
args <repeatable>
args to forward to function
Source:
Returns:
Object task object

registerTask(proc, options, cb)

Register an exising process to the task manager
Parameters:
Name Type Description
proc
options
Properties
Name Type Attributes Description
tid <optional>
a custom task id
sh <optional>
the shell command being executed
parseProgress <optional>
a function to parse the progress (or set taskManager.status[tid]);
cb
Source:

spawnTask(sh, options, cb)

Start a task process
Parameters:
Name Type Description
sh the command like in a shell
options optional options
Properties
Name Type Description
args Array of args to append to args from the sh line or if just the command is passed in to sh
options options to pass to spawn https://nodejs.org/api/child_process.html#child_processspawncommand-args-options
parseProgress (task, data, done, err) a function that should return the progress out of 1 from a stdout/err data string must return number or object containing val = number for progress bars. Alternatively set task.status directly in the cb to override or do you own thing independently
parseProgress (task, data, done, err) a function that should return the progress out of 1 from a stdout/err data string
options. (task, data) a function that should return the progress out of 1 from a stdout/err data string then args like in child_process.spawn
cb (tid ,data, isDone, isError) called when something happens data is stdout or stderro text
Source: