Improved stream mode to minimize complete failures.
This commit is contained in:
+32
-1
@@ -66,6 +66,7 @@ function createSceneStream({ batchId }) {
|
|||||||
const unsearchedIds = [];
|
const unsearchedIds = [];
|
||||||
const movieScenes = [];
|
const movieScenes = [];
|
||||||
const failed = [];
|
const failed = [];
|
||||||
|
const skipped = [];
|
||||||
|
|
||||||
let active = 0;
|
let active = 0;
|
||||||
let added = 0;
|
let added = 0;
|
||||||
@@ -241,7 +242,20 @@ function createSceneStream({ batchId }) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await fetcher.addEntities(stubs);
|
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 stubs.reduce(async (chain, stub) => {
|
||||||
await chain;
|
await chain;
|
||||||
@@ -264,16 +278,21 @@ function createSceneStream({ batchId }) {
|
|||||||
|
|
||||||
await updateSearch();
|
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) {
|
if (failed.length > 0) {
|
||||||
logger.warn(`Failed to store:\n${failed.join('\n')}`);
|
logger.warn(`Failed to store:\n${failed.join('\n')}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (skipped.length > 0) {
|
||||||
|
logger.warn(`Skipped:\n${skipped.join('\n')}`);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sceneIds,
|
sceneIds,
|
||||||
movieScenes,
|
movieScenes,
|
||||||
failed,
|
failed,
|
||||||
|
skipped,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,14 +306,26 @@ async function streamScenes(baseScenes = []) {
|
|||||||
|
|
||||||
const stream = createSceneStream({ batchId });
|
const stream = createSceneStream({ batchId });
|
||||||
|
|
||||||
|
let listingError = null;
|
||||||
|
|
||||||
|
try {
|
||||||
await stream.add(baseScenes);
|
await stream.add(baseScenes);
|
||||||
|
|
||||||
if (argv.latest || argv.upcoming || argv.channels || argv.networks || argv.movies) {
|
if (argv.latest || argv.upcoming || argv.channels || argv.networks || argv.movies) {
|
||||||
await fetchUpdates((channelStubs) => stream.add(channelStubs));
|
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();
|
const result = await stream.finish();
|
||||||
|
|
||||||
|
if (listingError) {
|
||||||
|
throw listingError; // the run still fails, after the stream is wrapped up
|
||||||
|
}
|
||||||
|
|
||||||
return { ...result, batchId };
|
return { ...result, batchId };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user