multi-tasks 1.2.5 → 1.2.6
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 +5 -1
- package/examples/example0/run.js +4 -1
- package/package.json +1 -1
- package/workers/master.js +7 -1
- package/workers/report/report_status.js +52 -0
package/README.md
CHANGED
|
@@ -43,7 +43,10 @@ multiTasks({
|
|
|
43
43
|
processTask,
|
|
44
44
|
multi_task_parent_folder: `C:/tmp-demo`, //a directory to store progress and results files, you can check the progress here
|
|
45
45
|
quotaOfEachTask:1, //The number of subtasks assigned to each worker at one time, the default is 1
|
|
46
|
-
numberOfWorkers: 6 //Assign how many workers are working in parallel, default is the number of cpu cores minus one
|
|
46
|
+
numberOfWorkers: 6, //Assign how many workers are working in parallel, default is the number of cpu cores minus one
|
|
47
|
+
onFinish: (report)=>{
|
|
48
|
+
console.log(report);//the execution report can be viewed here
|
|
49
|
+
}
|
|
47
50
|
});
|
|
48
51
|
|
|
49
52
|
```
|
|
@@ -71,6 +74,7 @@ node examples/example1/run
|
|
|
71
74
|
|
|
72
75
|
Changelog:
|
|
73
76
|
|
|
77
|
+
- 1.2.6 Support onFinish event
|
|
74
78
|
- 1.2.5 Rename numberOfWorks to numberOfWorkers, the old one are still supported ;-)
|
|
75
79
|
- 1.2.4 Fix: opt.numberOfWorkers not work
|
|
76
80
|
- 1.2.3 Update README
|
package/examples/example0/run.js
CHANGED
|
@@ -31,5 +31,8 @@ multiTasks({
|
|
|
31
31
|
processTask,
|
|
32
32
|
multi_task_parent_folder: `C:/tmp-demo`, //a directory to store progress and results files, you can check the progress here
|
|
33
33
|
quotaOfEachTask:1, //The number of subtasks assigned to each worker at one time, the default is 1
|
|
34
|
-
numberOfWorkers: 6 //Assign how many workers are working in parallel
|
|
34
|
+
numberOfWorkers: 6, //Assign how many workers are working in parallel
|
|
35
|
+
onFinish: (report)=>{
|
|
36
|
+
console.log(report);
|
|
37
|
+
}
|
|
35
38
|
});
|
package/package.json
CHANGED
package/workers/master.js
CHANGED
|
@@ -2,6 +2,7 @@ var fs = require('fs');
|
|
|
2
2
|
var pathutil = require('path');
|
|
3
3
|
const cluster = require('cluster');
|
|
4
4
|
const numCPUs = require('os').cpus().length;
|
|
5
|
+
const report_status = require('./report/report_status');
|
|
5
6
|
|
|
6
7
|
let MSG_REQUEST_TASKID = 'request_taskid';
|
|
7
8
|
/**
|
|
@@ -96,7 +97,12 @@ let run = (currentProducer, currentConsumer, opt)=>{
|
|
|
96
97
|
};
|
|
97
98
|
let dataPath = pathutil.resolve(taskFolder, `./extractTaskData-${masterId}.json`);
|
|
98
99
|
fs.writeFileSync(dataPath, JSON.stringify(dataForNextMission))
|
|
99
|
-
console.log('dataForNextMission=', dataPath)
|
|
100
|
+
console.log('dataForNextMission=', dataPath);
|
|
101
|
+
if(opt.onFinish) {
|
|
102
|
+
opt.taskFolder = taskFolder;
|
|
103
|
+
let report = report_status.getReport(opt);
|
|
104
|
+
opt.onFinish(report);
|
|
105
|
+
}
|
|
100
106
|
};
|
|
101
107
|
}
|
|
102
108
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
var pathutil = require('path');
|
|
3
|
+
|
|
4
|
+
function countDirectChildFiles(directoryPath) {
|
|
5
|
+
const files = fs.readdirSync(directoryPath);
|
|
6
|
+
const directChildFiles = files.filter(file => {
|
|
7
|
+
const filePath = pathutil.join(directoryPath, file);
|
|
8
|
+
return fs.statSync(filePath).isFile();
|
|
9
|
+
});
|
|
10
|
+
return directChildFiles;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
let getReport = (taskConfig)=>{
|
|
14
|
+
let {taskFolder} = taskConfig;
|
|
15
|
+
let folder_result_errors = pathutil.resolve(taskFolder, './results/errors');
|
|
16
|
+
let folder_result_succ = pathutil.resolve(taskFolder, './results/succ');
|
|
17
|
+
|
|
18
|
+
let folder_new = pathutil.resolve(taskFolder, './progress/new');
|
|
19
|
+
let folder_running = pathutil.resolve(taskFolder, './progress/running');
|
|
20
|
+
let folder_finished = pathutil.resolve(taskFolder, './progress/finished');
|
|
21
|
+
let folder_finished_with_errors = pathutil.resolve(taskFolder, './progress/finished_with_errors');
|
|
22
|
+
|
|
23
|
+
let files_new = countDirectChildFiles(folder_new);
|
|
24
|
+
let files_running = countDirectChildFiles(folder_running);
|
|
25
|
+
let files_finished = countDirectChildFiles(folder_finished);
|
|
26
|
+
let files_finished_with_errors = countDirectChildFiles(folder_finished_with_errors);
|
|
27
|
+
|
|
28
|
+
let report = {
|
|
29
|
+
taskConfig,
|
|
30
|
+
task_folders:{
|
|
31
|
+
folder_new,
|
|
32
|
+
folder_running,
|
|
33
|
+
folder_finished,
|
|
34
|
+
folder_finished_with_errors
|
|
35
|
+
},
|
|
36
|
+
result_folders:{
|
|
37
|
+
folder_result_errors,
|
|
38
|
+
folder_result_succ
|
|
39
|
+
},
|
|
40
|
+
tasks:{
|
|
41
|
+
new: files_new.length,
|
|
42
|
+
running: files_running.length,
|
|
43
|
+
finished: files_finished.length,
|
|
44
|
+
finished_with_errors: files_finished_with_errors.length,
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return report;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
module.exports = {
|
|
51
|
+
getReport
|
|
52
|
+
}
|