# supertask

> A task & queue environment ideal for distributed computing and execution

Latest version **2.1.0** (published 2016-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install supertask
pnpm add supertask
yarn add supertask
bun add supertask
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2016-01-17 |
| First published | 2016-01-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Schahriar SaffarShargh |
| Maintainers | schahriar |
| Keywords | supertask, queue, task, performance, cluster, parallel, parallelized, distributed |

## Links

- npm: https://www.npmjs.com/package/supertask
- Repository: https://github.com/schahriar/supertask
- Homepage: https://github.com/schahriar/supertask#readme
- Issues: https://github.com/schahriar/supertask/issues
- npm.io page: https://npm.io/package/supertask

## Dependencies (1)

- [double-ended-queue](https://npm.io/package/double-ended-queue.md) ^0.9.7

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 2.1.0 (latest) — 2016-01-17
- 2.0.0 — 2016-01-16
- 1.3.0 — 2016-01-08
- 1.2.4 — 2016-01-08
- 1.2.3 — 2016-01-07
- 1.2.2 — 2016-01-02
- 1.2.1 — 2016-01-02
- 1.2.0 — 2016-01-01
- 1.1.0 — 2016-01-01
- 1.0.0 — 2016-01-01

## README

# supertask
[![Build Status](https://travis-ci.org/schahriar/supertask.svg?branch=master)](https://travis-ci.org/schahriar/supertask)
[![Test Coverage](https://codeclimate.com/github/schahriar/supertask/badges/coverage.svg)](https://codeclimate.com/github/schahriar/supertask/coverage)

## Supertask is a NodeJS task queue designed for parallel and cluster execution.

**Supertask** was designed to run tasks in parallel and enable for a connected interface to distribute tasks across a network or cluster. A task can either be a local JavaScript function or in form of source which is then compiled and sandboxed through the VM. It utilizes a [**double-ended queue**](https://en.wikipedia.org/wiki/Double-ended_queue) to manage and execute given tasks.

 **Note that there is no underlying interface for parallelization or clustering and this module enables such features through tasks.**

# Installation
Note that Supertask requires *ES6* and is designed to run on NodeJS 4.x and above.
```javascript
npm install supertask
```

# Usage
Create a new local task with a unique name. **Note that a unique name is required for every task.**
```javascript
var Supertask = require('supertask');
var TaskManager = new Supertask();

var task = TaskManager.addLocal('taskname', function power(n, x, callback) {
    // n^x function
    callback(null, Math.pow(n,x));
});
```

Run task. You can pass arguments after name and before callback.

```javascript
TaskManager.do('taskname', 2, 4, function callback(error, result) {
    console.log("2^4 is equal to", result);
});
```

Add a foreign task
```javascript
// Source from network I/O etc.
var source = "module.exports = function power(n, x, callback) { callback(null, Math.pow(n,x)); }";
var task = TaskManager.addForeign('foreignPow', source);
```

Change permissions and globals of a task and precompilation
```javascript
var Supertask = require('supertask');
var TaskManager = new Supertask();

// Source from network I/O etc.
var source = "module.exports = function cmtp(y, callback) { callback(null, y * gx); }";

var task = TaskManager.addForeign('globalMultiply', source);
task.permissions(Supertask.ST_MINIMAL); // Allows limited require, Buffer, etc.
// gx will be available globally
task.globals({ gx: 2 });
// Compile Task through VM
task.precompile();
// Call Task (similar to TaskManager.do)
task.do(8, function(error, result) {
    // arg[0] * gx = 8 * 2 = 16
    console.log(result);
    // Output: 16
});
```

**Calling another task** within a task.
```javascript
...
// Source from network I/O etc.
var sourceF1 = "module.exports = function (a, b, callback) { callback(null, a*b); }";
var sourceF2 = "module.exports = function (a, b, callback) { this.call('multiply', a, b, callback); }";

TaskManager.addForeign('multiply', sourceF1);
var task = TaskManager.addForeign('Caller', source);
// Call Task (similar to TaskManager.do)
task.do(3, 7, function(error, result) {
    // 3 * 7
    console.log(result);
    // Output: 21
});
```

## What's the difference between a Task and a Function?
Functions can't be shared within Clusters or networks in JS unlike many other types that can be trasferred in form of JSON. That's because of **globals** and **closures**. If we could ignore closures and instead stick to globals we can pass the source of these functions across a network and re-compile then through the VM Core Module provided with NodeJS from source. In fact `require` itself uses VM to process modules. *Moreover Functions can be converted to Tasks but without [closures](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures). Although you can provide global variable access through Task#globals which can be useful at times.*

\**Above is an excerpt from `Understanding Tasks`* You can read the [entire guide here.](./documentation/Understanding_Tasks.md)

## API & Documentation
[Read more about tasks here.](./documentation/Understanding_Tasks.md)

[API documentation is available here.](./documentation/api.md)

## License
MIT © Schahriar SaffarShargh <info@schahriar.com>

---
_Source: https://npm.io/package/supertask · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
