mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
Add try catch in dump database
This commit is contained in:
parent
ce59d3f95f
commit
f5cfd6bfb5
1 changed files with 21 additions and 16 deletions
|
@ -197,24 +197,29 @@ async function queueDump(): Promise<void> {
|
|||
const startTime = Date.now();
|
||||
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,
|
||||
});
|
||||
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];
|
||||
|
||||
lastUpdate = startTime;
|
||||
} catch(e) {
|
||||
Logger.error(e);
|
||||
} finally {
|
||||
updateQueued = false;
|
||||
updateRunning = false;
|
||||
}
|
||||
latestDumpFiles = [...dumpFiles];
|
||||
|
||||
updateQueued = false;
|
||||
updateRunning = false;
|
||||
lastUpdate = startTime;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue