From f5cfd6bfb5b8bb9c26c8338b2cd3a6d510ed78b3 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 3 Jul 2021 17:26:59 -0400 Subject: [PATCH] Add try catch in dump database --- src/routes/dumpDatabase.ts | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/routes/dumpDatabase.ts b/src/routes/dumpDatabase.ts index cb2169a..5a590b5 100644 --- a/src/routes/dumpDatabase.ts +++ b/src/routes/dumpDatabase.ts @@ -197,24 +197,29 @@ async function queueDump(): Promise { 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, + }); + } + latestDumpFiles = [...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, - }); + lastUpdate = startTime; + } catch(e) { + Logger.error(e); + } finally { + updateQueued = false; + updateRunning = false; } - latestDumpFiles = [...dumpFiles]; - - updateQueued = false; - updateRunning = false; - lastUpdate = startTime; } }