multi-tasks 2.1.5 → 2.2.0

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 CHANGED
@@ -1,13 +1,14 @@
1
1
  # multi-tasks
2
- multi-tasks
3
2
 
4
- Install:
3
+ Multi-tasks is used to handle long-term and large-scale parallel computing tasks. It manages progress and tasks based on the file system, which means that even if the host crashes, tasks can be resumed based on file records.
4
+
5
+ ### Install:
5
6
 
6
7
  ```javascript
7
8
  npm install multi-tasks
8
9
  ```
9
10
 
10
- How to use:
11
+ ### How to use:
11
12
 
12
13
  ```javascript
13
14
  //see examples/example0
@@ -50,14 +51,7 @@ multiTasks({
50
51
 
51
52
  ```
52
53
 
53
- Have a try:
54
-
55
- ```shell
56
- node examples/example0/run
57
- node examples/example1/run
58
- ```
59
-
60
- More about the task processing function
54
+ ### More about the task processing function
61
55
 
62
56
  ```javascript
63
57
  //Example1, return a promise for async processes,
@@ -107,8 +101,24 @@ let processTask = (task, helper)=>{
107
101
 
108
102
  ```
109
103
 
110
- Changelog:
104
+ ### Resuming
105
+
106
+ Sometimes the task execution is interrupted due to some reasons (such as power outage), you can resume the execution like this
107
+
108
+ ```javascript
109
+
110
+ multiTasks({
111
+ initialTasks: `/myworks/my_scan_tasks/`, //Point 'initialTasks' to the interrupted task directory, multi-tasks will read the tasks in the 'new' folder and initialize them to 'initialTasks' and then continue execution
112
+ ...
113
+ ...//Other configurations remain unchanged
114
+ ...
115
+ });
116
+
117
+ ```
118
+
119
+ ### Changelog:
111
120
 
121
+ - 2.2.0 Support Resuming from an interrupted task
112
122
  - 2.1.2 Update readme
113
123
  - 2.1.1 Fix: recreate a new one when a worker collapsed unexpectedly.
114
124
  - 2.1.0 Add a new output directory "log" where you can view the process time of each subtask
@@ -140,10 +150,10 @@ Changelog:
140
150
  - 1.0.7 Remove moment
141
151
  - 1.0.6 Performance optimization
142
152
 
143
- Github:
153
+ ### Github:
144
154
 
145
155
  [https://github.com/zhanglei923/multi-tasks](https://github.com/zhanglei923/multi-tasks)
146
156
 
147
- Support / Bug Report:
157
+ ### Support / Bug Report:
148
158
 
149
159
  [zhangleisupport923@163.com](mailto:zhangleisupport923@163.com)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multi-tasks",
3
- "version": "2.1.5",
3
+ "version": "2.2.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -161,12 +161,16 @@ function subWorker(){
161
161
  //console.log('ssss', subTask)
162
162
  if(subTask){
163
163
  subTask.index = taskCount;//for v1 backward
164
- subTask.taskCount = taskCount;
164
+ subTask.taskCount = taskCount;
165
+ subTask.workerId = worker.id;
166
+ subTask.workerPid = process.pid;
165
167
  console.log(`[Task Start]: "${subTask.subid}"`, `pid=${process.pid}`, getDateTimeTxt());
166
168
  let sendMsg = (msg)=>{
167
169
  worker.send(msg);
168
170
  };
169
171
  let subTaskLog = {
172
+ workerId: worker.id,
173
+ workerPid: process.pid,
170
174
  taskCount,
171
175
  startTimestamp
172
176
  };
package/workers/index.js CHANGED
@@ -5,7 +5,7 @@ const backwardv1 = require('../utils/backward-v1');
5
5
 
6
6
  const _toAbsPath = (path)=>{
7
7
  if(!path) return path;
8
- if(pathUtil.isAbsolute(path))return;
8
+ if(pathUtil.isAbsolute(path))return path;
9
9
  let abspath = pathUtil.resolve(process.cwd(), path);
10
10
  return abspath;
11
11
  };
@@ -39,10 +39,29 @@ const restart = (config)=>{
39
39
  };
40
40
 
41
41
  const multiTasks = (config)=>{
42
- let {taskRootFolder, taskId} = config;
43
- let taskFolder = pathUtil.resolve(taskRootFolder, taskId);
42
+ let {initialTasks, taskRootFolder, taskId} = config;
43
+ let isResume = false;
44
44
 
45
- if(fs.existsSync(taskFolder)){
45
+ if(typeof initialTasks === 'string'){//might be an existing tasks folder
46
+ if(fs.existsSync(initialTasks)){
47
+ isResume = true;
48
+ config.taskRootFolder = pathUtil.dirname(initialTasks);
49
+ }else if(taskRootFolder){
50
+ let folder = pathUtil.resolve(taskRootFolder, initialTasks);
51
+ if(fs.existsSync(folder)){
52
+ isResume = true;
53
+ config.taskRootFolder = pathUtil.dirname(folder);;
54
+ }
55
+ }
56
+ if(!isResume) throw 'FATAL: initialTasks should be an array or a task root folder!';
57
+ }else{
58
+ let taskFolder = pathUtil.resolve(taskRootFolder, taskId);
59
+ if(fs.existsSync(taskFolder)){
60
+ isResume = true;
61
+ }
62
+ }
63
+
64
+ if(isResume){
46
65
  resume(config);
47
66
  }else{
48
67
  start(config);
@@ -54,4 +73,4 @@ multiTasks.start = start;
54
73
  multiTasks.restart = restart;
55
74
  multiTasks.resume = resume;
56
75
 
57
- module.exports = multiTasks;
76
+ module.exports = multiTasks;