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
+25 -13
+25 -13
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,13 +228,19 @@ while (performance.now() < t1 && regions.length > 0) {
} }
} }
console.log("Saving chunks..."); let isSaving = false;
async function save() {
if (isSaving) return;
await rm(`${CHUNKS_DIR}/*`, { force: true }); isSaving = true;
let totalFound = 0; console.log("Saving chunks...");
for (let i = 0; i < chunks.length; i++) { await rm(`${CHUNKS_DIR}/*`, { force: true });
let totalFound = 0;
for (let i = 0; i < chunks.length; i++) {
const path = `${CHUNKS_DIR}/chunk-${i}.dat.lz4`; const path = `${CHUNKS_DIR}/chunk-${i}.dat.lz4`;
const chunk = chunks[i]; const chunk = chunks[i];
const bytes = chunk.toBytes(); const bytes = chunk.toBytes();
@@ -240,14 +249,17 @@ for (let i = 0; i < chunks.length; i++) {
totalFound += chunk.size(); totalFound += chunk.size();
await Bun.write(path, compressed); await Bun.write(path, compressed);
}
const git = $.cwd(WORKING_DIR);
await git`git add .`.quiet();
await git`git commit --amend -m "ids update ${new Date().toISOString()}"`.quiet();
await git`git push --force-with-lease`.quiet();
console.log(
`Committed ${totalFound.toLocaleString()} total ids across ${chunkCount} chunks`,
);
} }
const git = $.cwd(WORKING_DIR); await save();
await git`git add .`.quiet();
await git`git commit --amend -m "ids update ${new Date().toISOString()}"`.quiet();
await git`git push --force-with-lease`.quiet();
console.log(
`Committed ${totalFound.toLocaleString()} total ids across ${chunkCount} chunks`,
);