From 5b10f89b0e5fcd264a404842b611ca1bdb12d653 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Mon, 30 Nov 2026 02:05:28 +0100 Subject: [PATCH] Improved stream mode to minimize complete failures. --- src/stream.js | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/stream.js b/src/stream.js index c8593d58..9420e48e 100644 --- a/src/stream.js +++ b/src/stream.js @@ -66,6 +66,7 @@ function createSceneStream({ batchId }) { const unsearchedIds = []; const movieScenes = []; const failed = []; + const skipped = []; let active = 0; let added = 0; @@ -241,7 +242,20 @@ function createSceneStream({ batchId }) { return; } - await fetcher.addEntities(stubs); + try { + await fetcher.addEntities(stubs); + } catch (error) { + // e.g. a database hiccup, skip this listing instead of aborting the run, unstored scenes are picked up by the next run + logger.error(`Failed to prepare ${stubs.length} scenes for deep scraping, skipping them: ${error.message}`); + + if (argv.debug) { + console.trace(error); + } + + skipped.push(...stubs.map((stub) => stub.url || `${stub.entity?.slug}:${stub.entryId}`)); + + return; + } await stubs.reduce(async (chain, stub) => { await chain; @@ -264,16 +278,21 @@ function createSceneStream({ batchId }) { await updateSearch(); - logger.info(`Streamed ${processed} scenes, stored ${sceneIds.length}${failed.length > 0 ? `, failed to store ${failed.length}` : ''}`); + logger.info(`Streamed ${processed} scenes, stored ${sceneIds.length}${failed.length > 0 ? `, failed to store ${failed.length}` : ''}${skipped.length > 0 ? `, skipped ${skipped.length}` : ''}`); if (failed.length > 0) { logger.warn(`Failed to store:\n${failed.join('\n')}`); } + if (skipped.length > 0) { + logger.warn(`Skipped:\n${skipped.join('\n')}`); + } + return { sceneIds, movieScenes, failed, + skipped, }; } @@ -287,14 +306,26 @@ async function streamScenes(baseScenes = []) { const stream = createSceneStream({ batchId }); - await stream.add(baseScenes); + let listingError = null; - if (argv.latest || argv.upcoming || argv.channels || argv.networks || argv.movies) { - await fetchUpdates((channelStubs) => stream.add(channelStubs)); + try { + await stream.add(baseScenes); + + if (argv.latest || argv.upcoming || argv.channels || argv.networks || argv.movies) { + await fetchUpdates((channelStubs) => stream.add(channelStubs)); + } + } catch (error) { + // still store and index what was already scraped, otherwise everything in flight is lost when the pool closes + logger.error(`Listing failed, finishing the scenes already queued: ${error.message}`); + listingError = error; } const result = await stream.finish(); + if (listingError) { + throw listingError; // the run still fails, after the stream is wrapped up + } + return { ...result, batchId }; }