mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-14 15:37:07 +03:00
Add try catch in dump database
This commit is contained in:
@@ -197,24 +197,29 @@ async function queueDump(): Promise<void> {
|
|||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
updateRunning = true;
|
updateRunning = true;
|
||||||
|
|
||||||
await removeOutdatedDumps(appExportPath);
|
try {
|
||||||
|
await removeOutdatedDumps(appExportPath);
|
||||||
|
|
||||||
const dumpFiles = [];
|
const dumpFiles = [];
|
||||||
|
|
||||||
|
for (const table of tables) {
|
||||||
|
const fileName = `${table.name}_${startTime}.csv`;
|
||||||
|
const file = `${postgresExportPath}/${fileName}`;
|
||||||
|
await db.prepare('run', `COPY (SELECT * FROM "${table.name}"${table.order ? ` ORDER BY "${table.order}"` : ``})
|
||||||
|
TO '${file}' WITH (FORMAT CSV, HEADER true);`);
|
||||||
|
dumpFiles.push({
|
||||||
|
fileName,
|
||||||
|
tableName: table.name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
latestDumpFiles = [...dumpFiles];
|
||||||
|
|
||||||
for (const table of tables) {
|
lastUpdate = startTime;
|
||||||
const fileName = `${table.name}_${startTime}.csv`;
|
} catch(e) {
|
||||||
const file = `${postgresExportPath}/${fileName}`;
|
Logger.error(e);
|
||||||
await db.prepare('run', `COPY (SELECT * FROM "${table.name}"${table.order ? ` ORDER BY "${table.order}"` : ``})
|
} finally {
|
||||||
TO '${file}' WITH (FORMAT CSV, HEADER true);`);
|
updateQueued = false;
|
||||||
dumpFiles.push({
|
updateRunning = false;
|
||||||
fileName,
|
|
||||||
tableName: table.name,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
latestDumpFiles = [...dumpFiles];
|
|
||||||
|
|
||||||
updateQueued = false;
|
|
||||||
updateRunning = false;
|
|
||||||
lastUpdate = startTime;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user