gitfleet 1.1.1 → 1.1.2
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/commands/pull.js +15 -2
- package/core/workerPool.js +16 -12
- package/package.json +1 -1
package/commands/pull.js
CHANGED
|
@@ -3,24 +3,37 @@ const { exec } = require("child_process");
|
|
|
3
3
|
|
|
4
4
|
function runGit(repo, command) {
|
|
5
5
|
return new Promise((resolve, reject) => {
|
|
6
|
+
|
|
6
7
|
exec(`git -C "${repo}" ${command}`, (err, stdout, stderr) => {
|
|
8
|
+
|
|
7
9
|
if (err) {
|
|
8
|
-
console.
|
|
10
|
+
console.log(`❌ ${repo}`);
|
|
11
|
+
console.log(stderr || err.message);
|
|
9
12
|
return reject(err);
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
console.log(`✔ ${repo}`);
|
|
16
|
+
|
|
17
|
+
if (stdout.trim()) {
|
|
18
|
+
console.log(stdout.trim());
|
|
19
|
+
}
|
|
20
|
+
|
|
13
21
|
resolve(stdout);
|
|
22
|
+
|
|
14
23
|
});
|
|
24
|
+
|
|
15
25
|
});
|
|
16
26
|
}
|
|
17
27
|
|
|
18
28
|
async function pullRepos(repos) {
|
|
19
|
-
|
|
29
|
+
|
|
30
|
+
const results = await runWorkerPool(
|
|
20
31
|
repos,
|
|
21
32
|
(repo) => runGit(repo, "pull"),
|
|
22
33
|
4
|
|
23
34
|
);
|
|
35
|
+
|
|
36
|
+
return results;
|
|
24
37
|
}
|
|
25
38
|
|
|
26
39
|
module.exports = pullRepos;
|
package/core/workerPool.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
const pLimit = require("p-limit");
|
|
2
|
-
|
|
3
2
|
const os = require("os");
|
|
4
|
-
const workers = os.cpus().length * 2;
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Run tasks in parallel with limited concurrency
|
|
8
|
-
* @param {Array} items
|
|
9
|
-
* @param {Function} task
|
|
10
|
-
* @param {number}
|
|
6
|
+
* @param {Array} items
|
|
7
|
+
* @param {Function} task
|
|
8
|
+
* @param {number} concurrency
|
|
11
9
|
*/
|
|
12
|
-
async function runWorkerPool(items, task,
|
|
13
|
-
|
|
10
|
+
async function runWorkerPool(items, task, concurrency = os.cpus().length) {
|
|
11
|
+
|
|
12
|
+
const limit = pLimit(concurrency);
|
|
14
13
|
|
|
15
14
|
const tasks = items.map(item =>
|
|
16
|
-
limit(() =>
|
|
15
|
+
limit(async () => {
|
|
16
|
+
try {
|
|
17
|
+
const result = await task(item);
|
|
18
|
+
return { item, success: true, result };
|
|
19
|
+
} catch (err) {
|
|
20
|
+
return { item, success: false, error: err };
|
|
21
|
+
}
|
|
22
|
+
})
|
|
17
23
|
);
|
|
18
24
|
|
|
19
|
-
return Promise.
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = { runWorkerPool };
|
|
25
|
+
return Promise.all(tasks);
|
|
26
|
+
}
|