save on exit

This commit is contained in:
tresabhi committed 2026-08-08 14:08:35 -05:00
1 parent ffd74de79f
commit 6d527a7170
1 file changed
+12
+12
View File
@@ -135,6 +135,9 @@ for (const region of regions) {
console.log("Starting discovery loop..."); console.log("Starting discovery loop...");
process.on("SIGINT", save);
process.on("SIGTERM", save);
const queue: { region: RegionDescriptor; url: string; size: number }[] = []; const queue: { region: RegionDescriptor; url: string; size: number }[] = [];
const applicationId = import.meta.env.PUBLIC_WARGAMING_APPLICATION_ID; const applicationId = import.meta.env.PUBLIC_WARGAMING_APPLICATION_ID;
const fields = "account_id%2C-account_id"; const fields = "account_id%2C-account_id";
@@ -225,6 +228,12 @@ while (performance.now() < t1 && regions.length > 0) {
} }
} }
let isSaving = false;
async function save() {
if (isSaving) return;
isSaving = true;
console.log("Saving chunks..."); console.log("Saving chunks...");
await rm(`${CHUNKS_DIR}/*`, { force: true }); await rm(`${CHUNKS_DIR}/*`, { force: true });
@@ -251,3 +260,6 @@ await git`git push --force-with-lease`.quiet();
console.log( console.log(
`Committed ${totalFound.toLocaleString()} total ids across ${chunkCount} chunks`, `Committed ${totalFound.toLocaleString()} total ids across ${chunkCount} chunks`,
); );
}
await save();