Skip to content

Commit c900253

Browse files
committed
only create tmp cleaner if paths to clean
1 parent 6b75ba8 commit c900253

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

apps/coordinator/src/checkpointer.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,7 @@ export class Checkpointer {
120120
this.simulatePushFailureSeconds = opts.simulatePushFailureSeconds ?? 300;
121121

122122
this.chaosMonkey = opts.chaosMonkey ?? new ChaosMonkey(!!process.env.CHAOS_MONKEY_ENABLED);
123-
124-
if (boolFromEnv("TMP_CLEANER_ENABLED", false)) {
125-
const pathsOverride = process.env.TMP_CLEANER_PATHS_OVERRIDE?.split(",") ?? [];
126-
127-
this.tmpCleaner = new TempFileCleaner({
128-
paths: pathsOverride.length ? pathsOverride : [Buildah.tmpDir, Crictl.checkpointDir],
129-
maxAgeMinutes: numFromEnv("TMP_CLEANER_MAX_AGE_MINUTES", 60),
130-
intervalSeconds: numFromEnv("TMP_CLEANER_INTERVAL_SECONDS", 300),
131-
leadingEdge: boolFromEnv("TMP_CLEANER_LEADING_EDGE", false),
132-
});
133-
134-
this.tmpCleaner.start();
135-
}
123+
this.tmpCleaner = this.#createTmpCleaner();
136124
}
137125

138126
async init(): Promise<CheckpointerInitializeReturn> {
@@ -647,4 +635,34 @@ export class Checkpointer {
647635
#getRunContainerName(suffix: string, attemptNumber?: number) {
648636
return `task-run-${suffix}${attemptNumber && attemptNumber > 1 ? `-att${attemptNumber}` : ""}`;
649637
}
638+
639+
#createTmpCleaner() {
640+
if (!boolFromEnv("TMP_CLEANER_ENABLED", false)) {
641+
return;
642+
}
643+
644+
const defaultPaths = [Buildah.tmpDir, Crictl.checkpointDir].filter(Boolean);
645+
const pathsOverride = process.env.TMP_CLEANER_PATHS_OVERRIDE?.split(",").filter(Boolean) ?? [];
646+
const paths = pathsOverride.length ? pathsOverride : defaultPaths;
647+
648+
if (paths.length === 0) {
649+
this.#logger.error("TempFileCleaner enabled but no paths to clean", {
650+
defaultPaths,
651+
pathsOverride,
652+
TMP_CLEANER_PATHS_OVERRIDE: process.env.TMP_CLEANER_PATHS_OVERRIDE,
653+
});
654+
655+
return;
656+
}
657+
const cleaner = new TempFileCleaner({
658+
paths,
659+
maxAgeMinutes: numFromEnv("TMP_CLEANER_MAX_AGE_MINUTES", 60),
660+
intervalSeconds: numFromEnv("TMP_CLEANER_INTERVAL_SECONDS", 300),
661+
leadingEdge: boolFromEnv("TMP_CLEANER_LEADING_EDGE", false),
662+
});
663+
664+
cleaner.start();
665+
666+
return cleaner;
667+
}
650668
}

0 commit comments

Comments
 (0)