multi-tasks 3.1.0 → 3.1.1

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.
Files changed (2) hide show
  1. package/README.md +31 -21
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -12,27 +12,36 @@ npm install multi-tasks
12
12
 
13
13
  ### API:
14
14
 
15
- - `multiTasks(config)` run tasks; auto-resumes if the task folder already exists or `initialTasks` points to one.
16
- - `multiTasks.start(config)` — always start a fresh run.
17
- - `multiTasks.resume(config)` — resume an interrupted run.
18
- - `multiTasks.restart(config)` — resume and also retry failed tasks (needs `config.taskFolder`).
19
- - `helper.createNewTasks(tasks)`create new tasks dynamically while processing.
20
- - `helper.emit(event, payload, option?)`broadcast an event to all workers (relayed by the master, best-effort); `option.includingMe` defaults to `true` — pass `{includingMe: false}` to exclude the sender. Payload must be JSON-serializable.
21
- - `helper.setListener(event, handler)`listen for broadcast events; one handler per event per worker process (re-registering replaces it), so calling it inside `processTask` is always safe; `handler(payload, meta)` gets `meta.fromWorkerId` and `meta.fromWorkerPid`. Broadcasts are runtime-only messages — not persisted, not replayed on resume.
22
- - `helper.emitSys(event, payload?)`send a system event to the master (consumed by the master itself, not relayed). Built-in event: `'TERMINATE_ALL_WORKERS'` force-kills all workers and exits the master; any other event goes to `config.setSysListener`.
23
- - Config options:
24
- - `initialTasks` — array of task objects, or a folder path string to resume from.
25
- - `processTask(task, helper)` — required; return a value or a Promise.
26
- - `taskRootFolder`root directory where progress and result files are stored.
27
- - `taskId`task folder name under `taskRootFolder`.
28
- - `taskFolder`full task folder path, required by `restart`.
29
- - `numberOfWorkers`how many worker processes run in parallel; a number, or a percentage string of CPU cores like `"50%"` (default).
30
- - `taskTimeout`optional, milliseconds; an overdue task fails with a timeout error.
31
- - `maxTaskRetries`optional, max times a failed task is auto-retried.
32
- - `autoCloseAfterCompletion`set `false` if you create new tasks dynamically.
33
- - `shouldTerminate(info)`return `true` to terminate the whole process.
34
- - `setSysListener(event, payload, meta)` optional, handle custom system events (sent via `helper.emitSys`) on the master; `meta` has `fromWorkerId` and `fromWorkerPid`.
35
- - `onFinish(report)`called once after all workers are done.
15
+ The API has three parts: the entry functions, the config options, and the `helper` object injected into `processTask`.
16
+
17
+ **Entry functions:**
18
+
19
+ - **`multiTasks(config)`**run tasks; auto-resumes if the task folder already exists or `initialTasks` points to one.
20
+ - **`multiTasks.start(config)`**always start a fresh run.
21
+ - **`multiTasks.resume(config)`**resume an interrupted run.
22
+ - **`multiTasks.restart(config)`**resume and also retry failed tasks (needs `config.taskFolder`).
23
+
24
+ **Config options:**
25
+
26
+ - **`initialTasks`**array of task objects, or a folder path string to resume from.
27
+ - **`processTask(task, helper)`** required; return a value or a Promise.
28
+ - **`taskRootFolder`**root directory where progress and result files are stored.
29
+ - **`taskId`**task folder name under `taskRootFolder`.
30
+ - **`taskFolder`**full task folder path, required by `restart`.
31
+ - **`numberOfWorkers`**how many worker processes run in parallel; a number, or a percentage string of CPU cores like `"50%"` (default).
32
+ - **`taskTimeout`**optional, milliseconds; an overdue task fails with a timeout error.
33
+ - **`maxTaskRetries`**optional, max times a failed task is auto-retried.
34
+ - **`autoCloseAfterCompletion`**set `false` if you create new tasks dynamically.
35
+ - **`shouldTerminate(info)`**return `true` to terminate the whole process.
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 are done.
38
+
39
+ **Task helper** (the `helper` object passed as the second argument of `processTask`):
40
+
41
+ - **`helper.createNewTasks(tasks)`** — create new tasks dynamically while processing.
42
+ - **`helper.emit(event, payload, option?)`** — broadcast an event to all workers (relayed by the master, best-effort); `option.includingMe` defaults to `true` — pass `{includingMe: false}` to exclude the sender. Payload must be JSON-serializable.
43
+ - **`helper.setListener(event, handler)`** — listen for broadcast events; one handler per event per worker process (re-registering replaces it), so calling it inside `processTask` is always safe; `handler(payload, meta)` gets `meta.fromWorkerId` and `meta.fromWorkerPid`. Broadcasts are runtime-only messages — not persisted, not replayed on resume.
44
+ - **`helper.emitSys(event, payload?)`** — send a system event to the master (consumed by the master itself, not relayed). Built-in event: `'TERMINATE_ALL_WORKERS'` force-kills all workers and exits the master; any other event goes to `config.setSysListener`.
36
45
 
37
46
  ### How to use:
38
47
 
@@ -210,6 +219,7 @@ The usage patterns documented above are covered by automated tests (unit tests i
210
219
 
211
220
  ### Changelog:
212
221
 
222
+ - 3.1.1 Fix readme documentation
213
223
  - 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)
214
224
  - 3.0.4 numberOfWorkers accepts a percentage string of CPU cores, e.g. "50%"
215
225
  - 3.0.3 Support 'maxTaskRetries'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multi-tasks",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "Multi-process task scheduling based on Node.js cluster, with crash resume and failed-task restart support",
5
5
  "main": "index.js",
6
6
  "files": [