multi-tasks 3.1.2 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,10 +31,10 @@ The API has three parts: the entry functions, the config options, and the `helpe
|
|
|
31
31
|
- **`numberOfWorkers`** — how many worker processes run in parallel; a number, or a percentage string of CPU cores like `"50%"` (default).
|
|
32
32
|
- **`taskTimeout`** — optional, milliseconds; an overdue task fails with a timeout error.
|
|
33
33
|
- **`maxTaskRetries`** — optional, max times a failed task is auto-retried.
|
|
34
|
-
- **`autoCloseAfterCompletion`** — set `
|
|
34
|
+
- **`autoCloseAfterCompletion`** — set `true` to kill workers and exit the process when no tasks are left; default is `false`, i.e. workers stay alive waiting for dynamically created tasks.
|
|
35
35
|
- **`shouldTerminate(info)`** — return `true` to terminate the whole process.
|
|
36
36
|
- **`setSysListener(event, payload, meta)`** — optional, handle custom system events (sent via `helper.emitSys`) on the master; `meta` has `fromWorkerId` and `fromWorkerPid`.
|
|
37
|
-
- **`onFinish(report)`** — called once after all workers
|
|
37
|
+
- **`onFinish(report)`** — called once after all workers exit (only when `autoCloseAfterCompletion` is `true`); `report` is an empty object for now.
|
|
38
38
|
|
|
39
39
|
**Task helper** (the `helper` object passed as the second argument of `processTask`):
|
|
40
40
|
|
|
@@ -77,7 +77,7 @@ multiTasks({
|
|
|
77
77
|
numberOfWorkers: 3, //how many workers are working in parallel
|
|
78
78
|
//taskTimeout: 30000, //optional, in milliseconds, an overdue task is treated as failed with a timeout error
|
|
79
79
|
//maxTaskRetries: 2, //optional, auto-retry a failed task (worker crash, processTask error, or timeout); retried tasks go back to the queue
|
|
80
|
-
//autoCloseAfterCompletion: true, //
|
|
80
|
+
//autoCloseAfterCompletion: true, //set true to exit the process when all tasks are done; keep it false (default) if you create new tasks dynamically
|
|
81
81
|
shouldTerminate:(info)=>{
|
|
82
82
|
//return true if you need to terminate the whole process
|
|
83
83
|
},
|
|
@@ -91,6 +91,8 @@ multiTasks({
|
|
|
91
91
|
### More about the task processing function
|
|
92
92
|
|
|
93
93
|
```javascript
|
|
94
|
+
//Examples 1-3 below are independent variants of processTask, use one at a time.
|
|
95
|
+
|
|
94
96
|
//Example1, return a promise for async processes,
|
|
95
97
|
// you can return a promise or a non-promise result,
|
|
96
98
|
// all result data can be found in the results/succ folder
|
|
@@ -209,6 +211,7 @@ multiTasks({
|
|
|
209
211
|
|
|
210
212
|
### Changelog:
|
|
211
213
|
|
|
214
|
+
- 3.1.3 Update README
|
|
212
215
|
- 3.1.2 Update README
|
|
213
216
|
- 3.1.1 Fix readme documentation
|
|
214
217
|
- 3.1.0 Support worker broadcast ('helper.emit' and 'helper.setListener') and system events ('helper.emitSys' and 'setSysListener', with built-in 'TERMINATE_ALL_WORKERS'); default numberOfWorkers is now "50%" of CPU cores (was core count minus 1)
|