multi-tasks 1.2.7 → 2.0.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/LICENSE +21 -21
- package/README.md +137 -97
- package/cmd.js +42 -0
- package/examples/example0/run-readme.js +88 -0
- package/examples/example0/run.js +52 -37
- 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/examples/example3-dynamicIncreasing/RunnerConsumer.js +175 -175
- package/examples/example3-dynamicIncreasing/RunnerProducer.js +48 -48
- package/examples/example3-dynamicIncreasing/run.js +35 -35
- package/examples/example3-dynamicIncreasing/util.js +45 -45
- package/index.js +3 -36
- package/monitors/cli.js +28 -0
- package/package.json +23 -22
- package/test/splitter.test.js +16 -16
- package/todo.txt +4 -0
- package/utils/asyncQueue.js +32 -0
- package/utils/backward-v1.js +11 -0
- package/utils/makedir.js +55 -24
- package/utils/randoms.js +15 -0
- package/utils/test/test_asyncqueue.js +116 -0
- package/utils/test_makedir.js +2 -2
- package/workers/Multithread.js +175 -0
- package/workers/TaskMgr.js +186 -0
- package/workers/WorkerMgr.js +31 -0
- package/workers/asMaster.js +71 -0
- package/workers/asWorker.js +14 -0
- package/workers/helper.js +22 -0
- package/workers/index.js +8 -0
- package/workers/SuperConsumer.js +0 -106
- package/workers/SuperProducer.js +0 -97
- package/workers/master.js +0 -171
- package/workers/report/report_status.js +0 -52
- package/workers/taskSplitter.js +0 -30
- package/workers/test/MyConsumer.js +0 -25
- package/workers/test/MyProducer.js +0 -26
- package/workers/test/test_master.js +0 -12
- package/workers/test/test_producer.js +0 -4
- package/workers/test/test_splitter.js +0 -7
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
let SuperConsumer = require('../../index').SuperConsumer;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
let _do = (mainTaskInfo, actions, callback)=>{
|
|
5
|
-
if(actions.length === 0) return callback({
|
|
6
|
-
data:'subtask finished, random data='+Math.random()
|
|
7
|
-
});
|
|
8
|
-
let actionData = actions.shift();
|
|
9
|
-
|
|
10
|
-
//start to write your process code here
|
|
11
|
-
|
|
12
|
-
console.log('actionData', actionData)
|
|
13
|
-
|
|
14
|
-
//end of your process code.
|
|
15
|
-
|
|
16
|
-
//trigger next task
|
|
17
|
-
_do(mainTaskInfo, actions, callback);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class TestConsumer extends SuperConsumer {
|
|
22
|
-
|
|
23
|
-
// constructor
|
|
24
|
-
constructor(taskname, parentfolder) {
|
|
25
|
-
super(taskname, parentfolder)
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
setTaskTrunkInfo(trunkInfo){
|
|
29
|
-
this.trunkInfo = trunkInfo;
|
|
30
|
-
}
|
|
31
|
-
run (mainTaskInfo, subTaskInfo, taskInfo, callback){
|
|
32
|
-
let actions = subTaskInfo.actions;
|
|
33
|
-
mainTaskInfo.defination = this.trunkInfo.defination;
|
|
34
|
-
_do(mainTaskInfo, actions, (result)=>{
|
|
35
|
-
callback(result)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
let SuperConsumer = require('../../index').SuperConsumer;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
let _do = (mainTaskInfo, actions, callback)=>{
|
|
5
|
+
if(actions.length === 0) return callback({
|
|
6
|
+
data:'subtask finished, random data='+Math.random()
|
|
7
|
+
});
|
|
8
|
+
let actionData = actions.shift();
|
|
9
|
+
|
|
10
|
+
//start to write your process code here
|
|
11
|
+
|
|
12
|
+
console.log('actionData', actionData)
|
|
13
|
+
|
|
14
|
+
//end of your process code.
|
|
15
|
+
|
|
16
|
+
//trigger next task
|
|
17
|
+
_do(mainTaskInfo, actions, callback);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TestConsumer extends SuperConsumer {
|
|
22
|
+
|
|
23
|
+
// constructor
|
|
24
|
+
constructor(taskname, parentfolder) {
|
|
25
|
+
super(taskname, parentfolder)
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
setTaskTrunkInfo(trunkInfo){
|
|
29
|
+
this.trunkInfo = trunkInfo;
|
|
30
|
+
}
|
|
31
|
+
run (mainTaskInfo, subTaskInfo, taskInfo, callback){
|
|
32
|
+
let actions = subTaskInfo.actions;
|
|
33
|
+
mainTaskInfo.defination = this.trunkInfo.defination;
|
|
34
|
+
_do(mainTaskInfo, actions, (result)=>{
|
|
35
|
+
callback(result)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
40
|
module.exports = TestConsumer;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
let SuperProducer = require('../../index').SuperProducer;
|
|
2
|
-
class TestProducer extends SuperProducer {
|
|
3
|
-
|
|
4
|
-
// constructor
|
|
5
|
-
constructor(taskname, parentfolder) {
|
|
6
|
-
super(taskname, parentfolder)
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
setTaskTrunkInfo(trunkInfo){
|
|
10
|
-
this.trunkInfo = trunkInfo;
|
|
11
|
-
}
|
|
12
|
-
getAllActions() {
|
|
13
|
-
/**
|
|
14
|
-
* Generate all your tasks in this method, return as an array;
|
|
15
|
-
* These data will be allocated to multiple threads (workers) for running;
|
|
16
|
-
* You can obtain each of the data and process it in the 'processTask' method of your consumer.
|
|
17
|
-
*
|
|
18
|
-
* **/
|
|
19
|
-
|
|
20
|
-
return new Promise((resolve, reject)=>{
|
|
21
|
-
let trunkInfo = this.trunkInfo;
|
|
22
|
-
let alltasks = []
|
|
23
|
-
for(let i=0;i<200;i++){
|
|
24
|
-
let task_props = {
|
|
25
|
-
index: i,
|
|
26
|
-
name: `task-${i}`,
|
|
27
|
-
description: `This prop is for a subtask`
|
|
28
|
-
};
|
|
29
|
-
alltasks.push(task_props);
|
|
30
|
-
}
|
|
31
|
-
resolve(alltasks);//return all your tasks as an array
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
let SuperProducer = require('../../index').SuperProducer;
|
|
2
|
+
class TestProducer extends SuperProducer {
|
|
3
|
+
|
|
4
|
+
// constructor
|
|
5
|
+
constructor(taskname, parentfolder) {
|
|
6
|
+
super(taskname, parentfolder)
|
|
7
|
+
|
|
8
|
+
}
|
|
9
|
+
setTaskTrunkInfo(trunkInfo){
|
|
10
|
+
this.trunkInfo = trunkInfo;
|
|
11
|
+
}
|
|
12
|
+
getAllActions() {
|
|
13
|
+
/**
|
|
14
|
+
* Generate all your tasks in this method, return as an array;
|
|
15
|
+
* These data will be allocated to multiple threads (workers) for running;
|
|
16
|
+
* You can obtain each of the data and process it in the 'processTask' method of your consumer.
|
|
17
|
+
*
|
|
18
|
+
* **/
|
|
19
|
+
|
|
20
|
+
return new Promise((resolve, reject)=>{
|
|
21
|
+
let trunkInfo = this.trunkInfo;
|
|
22
|
+
let alltasks = []
|
|
23
|
+
for(let i=0;i<200;i++){
|
|
24
|
+
let task_props = {
|
|
25
|
+
index: i,
|
|
26
|
+
name: `task-${i}`,
|
|
27
|
+
description: `This prop is for a subtask`
|
|
28
|
+
};
|
|
29
|
+
alltasks.push(task_props);
|
|
30
|
+
}
|
|
31
|
+
resolve(alltasks);//return all your tasks as an array
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
35
|
module.exports = TestProducer;
|
package/examples/example2/run.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
let RunnerProducer = require('./RunnerProducer');//switch to require from node_modules in your project
|
|
2
|
-
let RunnerConsumer = require('./RunnerConsumer');//switch to require from node_modules in your project
|
|
3
|
-
|
|
4
|
-
let taskId = Math.random()+'';
|
|
5
|
-
let multi_task_parent_folder = `C:/tmp-demo`;
|
|
6
|
-
|
|
7
|
-
let producer = new RunnerProducer(`workers_of_${taskId}`, multi_task_parent_folder)
|
|
8
|
-
let consumer = new RunnerConsumer();
|
|
9
|
-
let master = require('../../index').master;
|
|
10
|
-
|
|
11
|
-
console.log(producer.getTaskName())
|
|
12
|
-
//return;
|
|
13
|
-
|
|
14
|
-
let taskConfig = {
|
|
15
|
-
multi_task_parent_folder
|
|
16
|
-
}
|
|
17
|
-
//console.log(resp)
|
|
18
|
-
producer.setTaskTrunkInfo(taskConfig);
|
|
19
|
-
consumer.setTaskTrunkInfo(taskConfig)
|
|
20
|
-
master.run(producer, consumer, {
|
|
21
|
-
quotaOfEachTask:2,
|
|
22
|
-
numberOfWorkers: 6
|
|
1
|
+
let RunnerProducer = require('./RunnerProducer');//switch to require from node_modules in your project
|
|
2
|
+
let RunnerConsumer = require('./RunnerConsumer');//switch to require from node_modules in your project
|
|
3
|
+
|
|
4
|
+
let taskId = Math.random()+'';
|
|
5
|
+
let multi_task_parent_folder = `C:/tmp-demo`;
|
|
6
|
+
|
|
7
|
+
let producer = new RunnerProducer(`workers_of_${taskId}`, multi_task_parent_folder)
|
|
8
|
+
let consumer = new RunnerConsumer();
|
|
9
|
+
let master = require('../../index').master;
|
|
10
|
+
|
|
11
|
+
console.log(producer.getTaskName())
|
|
12
|
+
//return;
|
|
13
|
+
|
|
14
|
+
let taskConfig = {
|
|
15
|
+
multi_task_parent_folder
|
|
16
|
+
}
|
|
17
|
+
//console.log(resp)
|
|
18
|
+
producer.setTaskTrunkInfo(taskConfig);
|
|
19
|
+
consumer.setTaskTrunkInfo(taskConfig)
|
|
20
|
+
master.run(producer, consumer, {
|
|
21
|
+
quotaOfEachTask:2,
|
|
22
|
+
numberOfWorkers: 6
|
|
23
23
|
});
|
|
@@ -1,176 +1,176 @@
|
|
|
1
|
-
let fs = require('fs');
|
|
2
|
-
let pathutil = require('path');
|
|
3
|
-
const { spawn, exec } = require('child_process');
|
|
4
|
-
let SuperConsumer = require('../index').SuperConsumer;
|
|
5
|
-
let localUtil = require('./util');
|
|
6
|
-
const makeDir = require('../utils/makedir');
|
|
7
|
-
|
|
8
|
-
let thisroot = pathutil.parse(__filename).dir;
|
|
9
|
-
let garbagedir = pathutil.resolve(thisroot,`./tmp-garbage`);
|
|
10
|
-
makeDir.sync(garbagedir);
|
|
11
|
-
|
|
12
|
-
let loadTaskFile = (dir)=>{
|
|
13
|
-
var results = []
|
|
14
|
-
var list = fs.readdirSync(dir);
|
|
15
|
-
list.forEach(function(file) {
|
|
16
|
-
var stat;
|
|
17
|
-
try{
|
|
18
|
-
stat = fs.statSync(pathutil.resolve(dir, file))
|
|
19
|
-
}catch(e){
|
|
20
|
-
//Must try-catch, the file maybe deleted by other process
|
|
21
|
-
}
|
|
22
|
-
if (stat && !stat.isDirectory()) results.push({
|
|
23
|
-
file,
|
|
24
|
-
fpath: pathutil.resolve(dir, file)
|
|
25
|
-
});
|
|
26
|
-
})
|
|
27
|
-
//console.log(results);
|
|
28
|
-
return results;
|
|
29
|
-
};
|
|
30
|
-
let processTask = (moduleName, requestVersion, callback)=>{
|
|
31
|
-
let outputs = [];
|
|
32
|
-
let ls = spawn(`ls`, [], {cwd: garbagedir, shell: true});
|
|
33
|
-
ls.stdout.on('data', (data) => {
|
|
34
|
-
let stdout = data.toString();
|
|
35
|
-
outputs.push(stdout);
|
|
36
|
-
//console.log('[stdout]', stdout)
|
|
37
|
-
});
|
|
38
|
-
ls.stderr.on('data', (data) => {
|
|
39
|
-
let stdout = data.toString();
|
|
40
|
-
//console.log('[stderr]', stdout)
|
|
41
|
-
outputs.push(stdout);
|
|
42
|
-
});
|
|
43
|
-
ls.on('close', (code) => {
|
|
44
|
-
//console.log('[close]', code)
|
|
45
|
-
// if(code === 1) {
|
|
46
|
-
// console.log('[error], checkout failed!!')
|
|
47
|
-
// }
|
|
48
|
-
let succ = true;
|
|
49
|
-
let logTxt = outputs.join('');
|
|
50
|
-
|
|
51
|
-
if(logTxt.indexOf('ERR!')>=0 && logTxt.match(/ERR\!/g)) {
|
|
52
|
-
succ = false;
|
|
53
|
-
}
|
|
54
|
-
let logJson;
|
|
55
|
-
try{
|
|
56
|
-
logJson = JSON.parse(logTxt);
|
|
57
|
-
}catch(e){
|
|
58
|
-
console.log(e)
|
|
59
|
-
console.log(`at===`, moduleName, requestVersion)
|
|
60
|
-
console.log(`logTxt===`, logTxt)
|
|
61
|
-
succ = false;
|
|
62
|
-
}
|
|
63
|
-
if(succ && logJson){
|
|
64
|
-
if(!Array.isArray(logJson)){
|
|
65
|
-
logJson = [logJson];
|
|
66
|
-
};
|
|
67
|
-
let data = {
|
|
68
|
-
response: logJson,
|
|
69
|
-
__info__: {
|
|
70
|
-
moduleName,
|
|
71
|
-
requestVersion,
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
callback(true, data);
|
|
75
|
-
}else{
|
|
76
|
-
callback(false, logTxt);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let _do = (mainTaskInfo, actions, callback)=>{
|
|
83
|
-
let{dynamicTasksFolderNew, dynamicTasksFolderSucc, dynamicTasksFolderFail} = mainTaskInfo.defination;
|
|
84
|
-
let tasks = loadTaskFile(dynamicTasksFolderNew);
|
|
85
|
-
if(tasks.length === 0) return callback({data:'hahaha'+Math.random()});//stop!
|
|
86
|
-
|
|
87
|
-
tasks = localUtil.shuffleAnArray(tasks);//avoid file IO conflicts
|
|
88
|
-
|
|
89
|
-
let task;
|
|
90
|
-
let data;
|
|
91
|
-
while(!data){
|
|
92
|
-
task = tasks.shift();
|
|
93
|
-
try{
|
|
94
|
-
data = JSON.parse(fs.readFileSync(task.fpath, 'utf8'));
|
|
95
|
-
}catch(e){
|
|
96
|
-
console.log('xxxx')
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if(task && data){
|
|
101
|
-
let fpath = task.fpath;
|
|
102
|
-
{
|
|
103
|
-
//processing...
|
|
104
|
-
let {moduleName, requestVersion, fullnameMd5} = data.info;
|
|
105
|
-
let oldfPath = fpath;
|
|
106
|
-
let newfPath = pathutil.resolve(dynamicTasksFolderNew, `${fullnameMd5}.json`);
|
|
107
|
-
let succfPath = pathutil.resolve(dynamicTasksFolderSucc, `${fullnameMd5}.json`);
|
|
108
|
-
let errfPath = pathutil.resolve(dynamicTasksFolderFail, `${fullnameMd5}.json`);
|
|
109
|
-
if(fs.existsSync(succfPath) || fs.existsSync(errfPath)) {
|
|
110
|
-
console.log('exist...', process.pid, fullnameMd5);
|
|
111
|
-
if(fs.existsSync(newfPath))
|
|
112
|
-
try{
|
|
113
|
-
fs.unlinkSync(newfPath);
|
|
114
|
-
}catch(e){
|
|
115
|
-
console.log('remove failed', process.pid, newfPath, e);
|
|
116
|
-
}
|
|
117
|
-
_do(mainTaskInfo, actions, callback);
|
|
118
|
-
}else {
|
|
119
|
-
console.log('processing...', process.pid, fpath);
|
|
120
|
-
processTask(moduleName, requestVersion, (succ, logJson)=>{
|
|
121
|
-
if(succ){
|
|
122
|
-
fs.writeFileSync(succfPath, JSON.stringify(logJson));
|
|
123
|
-
logJson.response.forEach((item)=>{
|
|
124
|
-
if(item.dependencies){
|
|
125
|
-
for(let module2 in item.dependencies){
|
|
126
|
-
let version2 = item.dependencies[module2];
|
|
127
|
-
console.log('found new task', module2, version2);
|
|
128
|
-
localUtil.createNewTask(module2, version2, dynamicTasksFolderNew);//find new one, create a new task file
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}else{
|
|
133
|
-
console.log('ERR! failed', moduleName, requestVersion);
|
|
134
|
-
fs.writeFileSync(pathutil.resolve(dynamicTasksFolderFail, `${fullnameMd5}.json`), JSON.stringify({
|
|
135
|
-
moduleName, requestVersion,
|
|
136
|
-
msg: logJson
|
|
137
|
-
}));
|
|
138
|
-
}
|
|
139
|
-
_do(mainTaskInfo, actions, callback);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
if(fs.existsSync(oldfPath)){
|
|
143
|
-
try{
|
|
144
|
-
fs.unlinkSync(oldfPath);
|
|
145
|
-
}catch(e){
|
|
146
|
-
console.log('remove failed', process.pid, oldfPath, e);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}else{
|
|
151
|
-
console.log('__done2', process.pid)
|
|
152
|
-
return callback({data:'hahaha'+Math.random()});//stop!
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
class TestConsumer extends SuperConsumer {
|
|
158
|
-
// constructor
|
|
159
|
-
constructor(taskname, parentfolder) {
|
|
160
|
-
super(taskname, parentfolder)
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
setTaskTrunkInfo(trunkInfo){
|
|
164
|
-
this.trunkInfo = trunkInfo;
|
|
165
|
-
}
|
|
166
|
-
run (mainTaskInfo, subTaskInfo, taskInfo, callback){
|
|
167
|
-
//console.log(`this.trunkInfo===`, this.trunkInfo)
|
|
168
|
-
let actions = subTaskInfo.actions;
|
|
169
|
-
mainTaskInfo.defination = this.trunkInfo;
|
|
170
|
-
_do(mainTaskInfo, actions, (result)=>{
|
|
171
|
-
callback(result)
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
}
|
|
1
|
+
let fs = require('fs');
|
|
2
|
+
let pathutil = require('path');
|
|
3
|
+
const { spawn, exec } = require('child_process');
|
|
4
|
+
let SuperConsumer = require('../index').SuperConsumer;
|
|
5
|
+
let localUtil = require('./util');
|
|
6
|
+
const makeDir = require('../utils/makedir');
|
|
7
|
+
|
|
8
|
+
let thisroot = pathutil.parse(__filename).dir;
|
|
9
|
+
let garbagedir = pathutil.resolve(thisroot,`./tmp-garbage`);
|
|
10
|
+
makeDir.sync(garbagedir);
|
|
11
|
+
|
|
12
|
+
let loadTaskFile = (dir)=>{
|
|
13
|
+
var results = []
|
|
14
|
+
var list = fs.readdirSync(dir);
|
|
15
|
+
list.forEach(function(file) {
|
|
16
|
+
var stat;
|
|
17
|
+
try{
|
|
18
|
+
stat = fs.statSync(pathutil.resolve(dir, file))
|
|
19
|
+
}catch(e){
|
|
20
|
+
//Must try-catch, the file maybe deleted by other process
|
|
21
|
+
}
|
|
22
|
+
if (stat && !stat.isDirectory()) results.push({
|
|
23
|
+
file,
|
|
24
|
+
fpath: pathutil.resolve(dir, file)
|
|
25
|
+
});
|
|
26
|
+
})
|
|
27
|
+
//console.log(results);
|
|
28
|
+
return results;
|
|
29
|
+
};
|
|
30
|
+
let processTask = (moduleName, requestVersion, callback)=>{
|
|
31
|
+
let outputs = [];
|
|
32
|
+
let ls = spawn(`ls`, [], {cwd: garbagedir, shell: true});
|
|
33
|
+
ls.stdout.on('data', (data) => {
|
|
34
|
+
let stdout = data.toString();
|
|
35
|
+
outputs.push(stdout);
|
|
36
|
+
//console.log('[stdout]', stdout)
|
|
37
|
+
});
|
|
38
|
+
ls.stderr.on('data', (data) => {
|
|
39
|
+
let stdout = data.toString();
|
|
40
|
+
//console.log('[stderr]', stdout)
|
|
41
|
+
outputs.push(stdout);
|
|
42
|
+
});
|
|
43
|
+
ls.on('close', (code) => {
|
|
44
|
+
//console.log('[close]', code)
|
|
45
|
+
// if(code === 1) {
|
|
46
|
+
// console.log('[error], checkout failed!!')
|
|
47
|
+
// }
|
|
48
|
+
let succ = true;
|
|
49
|
+
let logTxt = outputs.join('');
|
|
50
|
+
|
|
51
|
+
if(logTxt.indexOf('ERR!')>=0 && logTxt.match(/ERR\!/g)) {
|
|
52
|
+
succ = false;
|
|
53
|
+
}
|
|
54
|
+
let logJson;
|
|
55
|
+
try{
|
|
56
|
+
logJson = JSON.parse(logTxt);
|
|
57
|
+
}catch(e){
|
|
58
|
+
console.log(e)
|
|
59
|
+
console.log(`at===`, moduleName, requestVersion)
|
|
60
|
+
console.log(`logTxt===`, logTxt)
|
|
61
|
+
succ = false;
|
|
62
|
+
}
|
|
63
|
+
if(succ && logJson){
|
|
64
|
+
if(!Array.isArray(logJson)){
|
|
65
|
+
logJson = [logJson];
|
|
66
|
+
};
|
|
67
|
+
let data = {
|
|
68
|
+
response: logJson,
|
|
69
|
+
__info__: {
|
|
70
|
+
moduleName,
|
|
71
|
+
requestVersion,
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
callback(true, data);
|
|
75
|
+
}else{
|
|
76
|
+
callback(false, logTxt);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let _do = (mainTaskInfo, actions, callback)=>{
|
|
83
|
+
let{dynamicTasksFolderNew, dynamicTasksFolderSucc, dynamicTasksFolderFail} = mainTaskInfo.defination;
|
|
84
|
+
let tasks = loadTaskFile(dynamicTasksFolderNew);
|
|
85
|
+
if(tasks.length === 0) return callback({data:'hahaha'+Math.random()});//stop!
|
|
86
|
+
|
|
87
|
+
tasks = localUtil.shuffleAnArray(tasks);//avoid file IO conflicts
|
|
88
|
+
|
|
89
|
+
let task;
|
|
90
|
+
let data;
|
|
91
|
+
while(!data){
|
|
92
|
+
task = tasks.shift();
|
|
93
|
+
try{
|
|
94
|
+
data = JSON.parse(fs.readFileSync(task.fpath, 'utf8'));
|
|
95
|
+
}catch(e){
|
|
96
|
+
console.log('xxxx')
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if(task && data){
|
|
101
|
+
let fpath = task.fpath;
|
|
102
|
+
{
|
|
103
|
+
//processing...
|
|
104
|
+
let {moduleName, requestVersion, fullnameMd5} = data.info;
|
|
105
|
+
let oldfPath = fpath;
|
|
106
|
+
let newfPath = pathutil.resolve(dynamicTasksFolderNew, `${fullnameMd5}.json`);
|
|
107
|
+
let succfPath = pathutil.resolve(dynamicTasksFolderSucc, `${fullnameMd5}.json`);
|
|
108
|
+
let errfPath = pathutil.resolve(dynamicTasksFolderFail, `${fullnameMd5}.json`);
|
|
109
|
+
if(fs.existsSync(succfPath) || fs.existsSync(errfPath)) {
|
|
110
|
+
console.log('exist...', process.pid, fullnameMd5);
|
|
111
|
+
if(fs.existsSync(newfPath))
|
|
112
|
+
try{
|
|
113
|
+
fs.unlinkSync(newfPath);
|
|
114
|
+
}catch(e){
|
|
115
|
+
console.log('remove failed', process.pid, newfPath, e);
|
|
116
|
+
}
|
|
117
|
+
_do(mainTaskInfo, actions, callback);
|
|
118
|
+
}else {
|
|
119
|
+
console.log('processing...', process.pid, fpath);
|
|
120
|
+
processTask(moduleName, requestVersion, (succ, logJson)=>{
|
|
121
|
+
if(succ){
|
|
122
|
+
fs.writeFileSync(succfPath, JSON.stringify(logJson));
|
|
123
|
+
logJson.response.forEach((item)=>{
|
|
124
|
+
if(item.dependencies){
|
|
125
|
+
for(let module2 in item.dependencies){
|
|
126
|
+
let version2 = item.dependencies[module2];
|
|
127
|
+
console.log('found new task', module2, version2);
|
|
128
|
+
localUtil.createNewTask(module2, version2, dynamicTasksFolderNew);//find new one, create a new task file
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}else{
|
|
133
|
+
console.log('ERR! failed', moduleName, requestVersion);
|
|
134
|
+
fs.writeFileSync(pathutil.resolve(dynamicTasksFolderFail, `${fullnameMd5}.json`), JSON.stringify({
|
|
135
|
+
moduleName, requestVersion,
|
|
136
|
+
msg: logJson
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
_do(mainTaskInfo, actions, callback);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if(fs.existsSync(oldfPath)){
|
|
143
|
+
try{
|
|
144
|
+
fs.unlinkSync(oldfPath);
|
|
145
|
+
}catch(e){
|
|
146
|
+
console.log('remove failed', process.pid, oldfPath, e);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}else{
|
|
151
|
+
console.log('__done2', process.pid)
|
|
152
|
+
return callback({data:'hahaha'+Math.random()});//stop!
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class TestConsumer extends SuperConsumer {
|
|
158
|
+
// constructor
|
|
159
|
+
constructor(taskname, parentfolder) {
|
|
160
|
+
super(taskname, parentfolder)
|
|
161
|
+
|
|
162
|
+
}
|
|
163
|
+
setTaskTrunkInfo(trunkInfo){
|
|
164
|
+
this.trunkInfo = trunkInfo;
|
|
165
|
+
}
|
|
166
|
+
run (mainTaskInfo, subTaskInfo, taskInfo, callback){
|
|
167
|
+
//console.log(`this.trunkInfo===`, this.trunkInfo)
|
|
168
|
+
let actions = subTaskInfo.actions;
|
|
169
|
+
mainTaskInfo.defination = this.trunkInfo;
|
|
170
|
+
_do(mainTaskInfo, actions, (result)=>{
|
|
171
|
+
callback(result)
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
176
|
module.exports = TestConsumer;
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
let SuperProducer = require('../index').SuperProducer;
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
let pathutil = require('path');
|
|
4
|
-
|
|
5
|
-
let thisroot = pathutil.parse(__filename).dir;
|
|
6
|
-
|
|
7
|
-
let localUtil = require('./util')
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let createInitialTasks = (info)=>{
|
|
11
|
-
let succList = JSON.parse(fs.readFileSync(pathutil.resolve(thisroot,'../tmp/version_succList.json'), 'utf8'));
|
|
12
|
-
//succList = succList.slice(0, 20);
|
|
13
|
-
succList.forEach((item)=>{
|
|
14
|
-
let {moduleName, requestVersion} = item;
|
|
15
|
-
localUtil.createNewTask(moduleName, requestVersion, info.dynamicTasksFolderNew);
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class TestProducer extends SuperProducer {
|
|
22
|
-
|
|
23
|
-
// constructor
|
|
24
|
-
constructor(taskname, parentfolder) {
|
|
25
|
-
super(taskname, parentfolder)
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
setTaskTrunkInfo(trunkInfo){
|
|
29
|
-
this.trunkInfo = trunkInfo;
|
|
30
|
-
}
|
|
31
|
-
getAllActions() {
|
|
32
|
-
createInitialTasks(this.trunkInfo);
|
|
33
|
-
return new Promise((resolve, reject)=>{
|
|
34
|
-
let trunkInfo = this.trunkInfo;
|
|
35
|
-
let {NUMBER_OF_WORKS} = trunkInfo;
|
|
36
|
-
//console.log(this.trunkInfo)
|
|
37
|
-
//throw repos.length+'ff'+repos2.length
|
|
38
|
-
//here, IGNORED_repoRegexStringList
|
|
39
|
-
let alltasks = []
|
|
40
|
-
for(let i=0;i<NUMBER_OF_WORKS;i++){//the task was driven by files, not here
|
|
41
|
-
alltasks.push({
|
|
42
|
-
num:i
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
resolve(alltasks);
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
let SuperProducer = require('../index').SuperProducer;
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
let pathutil = require('path');
|
|
4
|
+
|
|
5
|
+
let thisroot = pathutil.parse(__filename).dir;
|
|
6
|
+
|
|
7
|
+
let localUtil = require('./util')
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
let createInitialTasks = (info)=>{
|
|
11
|
+
let succList = JSON.parse(fs.readFileSync(pathutil.resolve(thisroot,'../tmp/version_succList.json'), 'utf8'));
|
|
12
|
+
//succList = succList.slice(0, 20);
|
|
13
|
+
succList.forEach((item)=>{
|
|
14
|
+
let {moduleName, requestVersion} = item;
|
|
15
|
+
localUtil.createNewTask(moduleName, requestVersion, info.dynamicTasksFolderNew);
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TestProducer extends SuperProducer {
|
|
22
|
+
|
|
23
|
+
// constructor
|
|
24
|
+
constructor(taskname, parentfolder) {
|
|
25
|
+
super(taskname, parentfolder)
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
setTaskTrunkInfo(trunkInfo){
|
|
29
|
+
this.trunkInfo = trunkInfo;
|
|
30
|
+
}
|
|
31
|
+
getAllActions() {
|
|
32
|
+
createInitialTasks(this.trunkInfo);
|
|
33
|
+
return new Promise((resolve, reject)=>{
|
|
34
|
+
let trunkInfo = this.trunkInfo;
|
|
35
|
+
let {NUMBER_OF_WORKS} = trunkInfo;
|
|
36
|
+
//console.log(this.trunkInfo)
|
|
37
|
+
//throw repos.length+'ff'+repos2.length
|
|
38
|
+
//here, IGNORED_repoRegexStringList
|
|
39
|
+
let alltasks = []
|
|
40
|
+
for(let i=0;i<NUMBER_OF_WORKS;i++){//the task was driven by files, not here
|
|
41
|
+
alltasks.push({
|
|
42
|
+
num:i
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
resolve(alltasks);
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
49
|
module.exports = TestProducer;
|