From 1da9dce0d363e913896e600b86d8586d3a3d5e22 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 16 Jan 2023 09:10:36 +0000 Subject: [PATCH] Persist list of rooms that failed to import to easily review afterwards This way if we can more easily look at the results after the fact when the import finishes and we may or may not have disconnected from the shell session with all of that info. Follow-up to https://gitlab.com/gitterHQ/webapp/-/merge_requests/2313 Part of https://gitlab.com/gitterHQ/webapp/-/issues/2609 --- ...tter-to-matrix-historical-import-worker.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/scripts/utils/gitter-to-matrix-historical-import-worker.js b/scripts/utils/gitter-to-matrix-historical-import-worker.js index 358916a61c..c899e07bf1 100755 --- a/scripts/utils/gitter-to-matrix-historical-import-worker.js +++ b/scripts/utils/gitter-to-matrix-historical-import-worker.js @@ -233,6 +233,34 @@ async function getRoomIdResumePosition() { } } +const failedRoomIdsFilePath = path.join(tempDirectory, `./_failed-room-ids-${Date.now()}.json`); +async function persistFailedRoomIds(failedRoomIds) { + const failedRoomIdsToPersist = failedRoomIds || []; + + try { + logger.info( + `Writing failedRoomIds (${failedRoomIdsToPersist.length}) disk failedRoomIdsFilePath=${failedRoomIdsFilePath}` + ); + await fs.writeFile(failedRoomIdsFilePath, JSON.stringify(failedRoomIdsToPersist)); + } catch (err) { + logger.error(`Problem persisting failedRoomIds file to disk`, { exception: err }); + } +} + +const failedRoomInfosFilePath = path.join(tempDirectory, `./_failed-room-infos-${Date.now()}.json`); +async function persistFailedRoomInfos(failedRoomInfos) { + const failedRoomInfosToPersist = failedRoomInfos || []; + + try { + logger.info( + `Writing failedRoomInfos (${failedRoomInfosToPersist.length}) disk failedRoomInfosFilePath=${failedRoomInfosFilePath}` + ); + await fs.writeFile(failedRoomInfosFilePath, JSON.stringify(failedRoomInfosToPersist)); + } catch (err) { + logger.error(`Problem persisting failedRoomInfos file to disk`, { exception: err }); + } +} + // eslint-disable-next-line max-statements async function exec() { logger.info('Setting up Matrix bridge'); @@ -370,6 +398,10 @@ async function exec() { ); const failedRoomIds = concurrentQueue.getFailedItemIds(); + // Persist this even if no rooms failed so it's easy to tell whether or not we + // succeeded in writing anything out. It's better to know nothing failed than whether + // or not we actually made it to the end. + await persistFailedRoomIds(failedRoomIds); if (failedRoomIds.length === 0) { logger.info( `Successfully imported all historical messages for all rooms (aprox. ${eventsImportedRunningTotal} messages)` @@ -394,6 +426,7 @@ async function exec() { .join('\n'), `\n}` ); + await persistFailedRoomInfos(failedRoomInfos); } }