multi-tasks 2.0.2 → 2.0.4
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/LICENSE +21 -21
- package/README.md +144 -140
- package/cmd.js +41 -41
- package/examples/example0/run-readme.js +87 -87
- package/examples/example0/run.js +52 -52
- package/examples/example1/RunnerConsumer.js +25 -25
- package/examples/example1/RunnerProducer.js +34 -34
- package/examples/example1/run.js +8 -8
- package/examples/example2/RunnerConsumer.js +39 -39
- package/examples/example2/RunnerProducer.js +34 -34
- package/examples/example2/run.js +22 -22
- package/index.js +3 -3
- package/monitors/cli.js +28 -28
- package/package.json +23 -23
- package/test/splitter.test.js +16 -16
- package/test/test_resume/step1_start_and_crash.js +56 -0
- package/test/test_resume/step2_resume.js +22 -0
- package/test/test_resume/test.sh +4 -0
- package/todo.txt +3 -3
- package/utils/asyncQueue.js +35 -35
- package/utils/backward-v1.js +10 -10
- package/utils/makedir.js +40 -54
- package/utils/randoms.js +21 -15
- package/utils/test/test_asyncqueue.js +115 -115
- package/utils/test_makedir.js +2 -2
- package/workers/Multithread.js +209 -197
- package/workers/TaskMgr.js +212 -185
- package/workers/WorkerMgr.js +30 -30
- package/workers/asMaster.js +115 -70
- package/workers/asWorker.js +13 -13
- package/workers/helper.js +24 -21
- package/workers/index.js +56 -42
package/workers/asWorker.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var fs = require('fs');
|
|
2
|
-
var pathutil = require('path');
|
|
3
|
-
const numCPUs = require('os').cpus().length;
|
|
4
|
-
|
|
5
|
-
let MSG_REQUEST_TASKID = 'request_taskid';
|
|
6
|
-
|
|
7
|
-
const TaskMgr = require('./TaskMgr');
|
|
8
|
-
|
|
9
|
-
const init = (config, worker)=>{
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
module.exports = {
|
|
13
|
-
init
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
var pathutil = require('path');
|
|
3
|
+
const numCPUs = require('os').cpus().length;
|
|
4
|
+
|
|
5
|
+
let MSG_REQUEST_TASKID = 'request_taskid';
|
|
6
|
+
|
|
7
|
+
const TaskMgr = require('./TaskMgr');
|
|
8
|
+
|
|
9
|
+
const init = (config, worker)=>{
|
|
10
|
+
|
|
11
|
+
};
|
|
12
|
+
module.exports = {
|
|
13
|
+
init
|
|
14
14
|
};
|
package/workers/helper.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
let fs = require('fs');
|
|
2
|
-
let pathutil = require('path');
|
|
3
|
-
|
|
4
|
-
let TaskMgr = require('./TaskMgr');
|
|
5
|
-
|
|
6
|
-
let myconfig;
|
|
7
|
-
const load = (config)=>{
|
|
8
|
-
myconfig = config;
|
|
9
|
-
};
|
|
10
|
-
const createNewTasks = (tasks)=>{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
let fs = require('fs');
|
|
2
|
+
let pathutil = require('path');
|
|
3
|
+
|
|
4
|
+
let TaskMgr = require('./TaskMgr');
|
|
5
|
+
|
|
6
|
+
let myconfig;
|
|
7
|
+
const load = (config)=>{
|
|
8
|
+
myconfig = config;
|
|
9
|
+
};
|
|
10
|
+
const createNewTasks = (tasks)=>{
|
|
11
|
+
if (!Array.isArray(tasks)) tasks = [tasks];
|
|
12
|
+
TaskMgr.load(myconfig);
|
|
13
|
+
tasks.forEach((task)=>{
|
|
14
|
+
console.log('Creating new task', task)
|
|
15
|
+
TaskMgr.createNewTask(task);
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const setGlobalParams = (params)=>{
|
|
19
|
+
//will be overridden in Multithread
|
|
20
|
+
};
|
|
21
|
+
module.exports = {
|
|
22
|
+
load,
|
|
23
|
+
createNewTasks,
|
|
24
|
+
setGlobalParams
|
|
22
25
|
};
|
package/workers/index.js
CHANGED
|
@@ -1,43 +1,57 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
config
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
config =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
multiTasks
|
|
42
|
-
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const pathUtil = require('path');
|
|
3
|
+
const Multithread = require('./Multithread');
|
|
4
|
+
const backwardv1 = require('../utils/backward-v1');
|
|
5
|
+
|
|
6
|
+
const _toAbsPath = (path)=>{
|
|
7
|
+
if(!path) return path;
|
|
8
|
+
if(pathUtil.isAbsolute(path))return;
|
|
9
|
+
let abspath = pathUtil.resolve(process.cwd(), path);
|
|
10
|
+
return abspath;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const start = (config)=>{
|
|
14
|
+
config = backwardv1.v1tov2(config);
|
|
15
|
+
|
|
16
|
+
config.taskRootFolder = _toAbsPath(config.taskRootFolder);
|
|
17
|
+
config.taskFolder = _toAbsPath(config.taskFolder);
|
|
18
|
+
|
|
19
|
+
Multithread.start(config);
|
|
20
|
+
};
|
|
21
|
+
const resume = (config)=>{
|
|
22
|
+
config = backwardv1.v1tov2(config);
|
|
23
|
+
config.__resume = true;
|
|
24
|
+
|
|
25
|
+
config.initialTasks = [];
|
|
26
|
+
|
|
27
|
+
config.taskRootFolder = _toAbsPath(config.taskRootFolder);
|
|
28
|
+
config.taskFolder = _toAbsPath(config.taskFolder);
|
|
29
|
+
|
|
30
|
+
Multithread.start(config);
|
|
31
|
+
};
|
|
32
|
+
const restart = (config)=>{
|
|
33
|
+
config = backwardv1.v1tov2(config);
|
|
34
|
+
let {taskFolder} = config;
|
|
35
|
+
if(!taskFolder){
|
|
36
|
+
console.log('[ERROR]', 'method resume need param "taskFolder"')
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const multiTasks = (config)=>{
|
|
42
|
+
let {taskRootFolder, taskId} = config;
|
|
43
|
+
let taskFolder = pathUtil.resolve(taskRootFolder, taskId);
|
|
44
|
+
|
|
45
|
+
if(fs.existsSync(taskFolder)){
|
|
46
|
+
resume(config);
|
|
47
|
+
}else{
|
|
48
|
+
start(config);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
multiTasks.start = start;
|
|
54
|
+
multiTasks.restart = restart;
|
|
55
|
+
multiTasks.resume = resume;
|
|
56
|
+
|
|
43
57
|
module.exports = multiTasks;
|