https://github.com/inlustra/task-runner
A child-process management tool and sequencer... it's a tiny pipeline for node
https://github.com/inlustra/task-runner
Last synced: 6 months ago
JSON representation
A child-process management tool and sequencer... it's a tiny pipeline for node
- Host: GitHub
- URL: https://github.com/inlustra/task-runner
- Owner: Inlustra
- Created: 2018-02-02T19:12:05.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-12T07:02:23.000Z (over 8 years ago)
- Last Synced: 2025-02-11T09:42:32.564Z (over 1 year ago)
- Language: TypeScript
- Homepage: http://npmjs.com/package/@inlustra/task-runner
- Size: 32.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Inlustra's Task Runner
A sub-task manager/pipeline to handle child processes.
## Install
```
npm i @inlustra/task-manager
```
## TL:DR
Takes jobs (Child Processes) and handles piping up to a single stream across processes.
A Task is made up of multiple jobs with a previous job condition (eg. the previous job must be a success)
* Jobs are run consecutively
* All stage updates (Complete, Error, Cancelled, Skipped) are bubbled up through events.
* Handles errors without blowing up (If not handled explicitly!)
### The simplest way to get tasks running one after the other
Create a task, made up of multiple jobs, this is the equivalent of a pipeline
```javascript
const task = {
name: 'A Simple Task',
description: 'A task to list some files',
jobs: [
new ShellJob('ls ./'), // List the files
new ShellJob('sleep 5'), // Sleep for 5 seconds
new ShellJob('exit 1'), // Then error
new ShellJob('echo "This won\'t appear!"') // The task runner won't run this job
]
}
const taskHandler = new TaskHandler(task)
taskHandler.on(TaskHandler.Events.STAGE_UPDATE, (stages) => {
console.log('The next stage in the task has run!')
console.log(stages)
})
```
## Using the task runner to add tasks
```javascript
const task = {
name: 'A Simple Task',
description: 'A task to list some files',
jobs: [
new ShellJob('ls ./'), // List the files
new ShellJob('sleep 5'), // Sleep for 5 seconds
new ShellJob('exit 1'), // Then error
new ShellJob('echo "This won\'t appear!"') // The task runner won't run this job
]
}
```
Register the task, add your pipes and start it!
```javascript
const taskRunner = new TaskRunner()
taskRunner.addGlobalPipe(process.stdout) // Will print all outputs from any tasks to the console
const taskKey = taskRunner.register(task)
taskRunner.addTaskPipe(taskKey, fs.createWriteStream('./'))
```
# TODO
- Document the options available (Jobs can run on error)
- Document the Event types in TaskHandler and TaskRunner
- Bubble up errors to the developer