Improved stream mode to minimize complete failures.

This commit is contained in:
DebaucheryLibrarian
2026-11-30 02:05:28 +01:00
parent d1503b98e2
commit 5b10f89b0e
+36 -5
View File
@@ -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 };
}