Skip to content

Commit 9a04636

Browse files
committed
fix: try to prevent OOM
1 parent b076c1f commit 9a04636

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lib/batch/tasks/init-job-repo.task.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
cloneRepo,
66
pullLatest,
77
} from '../../services/git.service';
8+
import { wait } from '../../utils/wait';
89
import { Context } from '../../interface';
910
import {
1011
directoryExists,
@@ -19,21 +20,26 @@ export function initJobRepo(job: string): ListrTask {
1920
const { workspacePath, verbose } = ctx.options;
2021
const repoName = getRepoNameFromUrl(job);
2122
const repoPath = pathJoin(workspacePath, repoName);
22-
if (!directoryExists(repoPath)) {
23-
await cloneRepo(job, workspacePath);
24-
task.title = `${task.title}, cloned`;
25-
} else {
26-
try {
27-
await pullLatest(repoPath);
28-
task.title = `${task.title}, updated`;
29-
} catch (error) {
30-
task.title = `${task.title}, git pull failed, remove and retry to clone`;
31-
removeDirectoryRecursive(repoPath);
23+
try {
24+
if (!directoryExists(repoPath)) {
3225
await cloneRepo(job, workspacePath);
3326
task.title = `${task.title}, cloned`;
27+
} else {
28+
try {
29+
await pullLatest(repoPath);
30+
task.title = `${task.title}, updated`;
31+
} catch (error) {
32+
task.title = `${task.title}, git pull failed, remove and retry to clone`;
33+
removeDirectoryRecursive(repoPath);
34+
await cloneRepo(job, workspacePath);
35+
task.title = `${task.title}, cloned`;
36+
}
3437
}
38+
process.chdir(repoPath);
39+
} catch (error: any) {
40+
await wait();
41+
throw new error();
3542
}
36-
process.chdir(repoPath);
3743
},
3844
};
3945
}

0 commit comments

Comments
 (0)