mirror of
https://github.com/georgemandis/bubo-rss.git
synced 2024-11-23 12:24:23 +00:00
Fixing a bug where failing to fetch a feed could make Bubo hang
This commit is contained in:
parent
04696e9df6
commit
5ebc0d4952
31
src/index.ts
31
src/index.ts
@ -66,7 +66,11 @@ let completed = 0;
|
|||||||
* and we want to build the static output.
|
* and we want to build the static output.
|
||||||
*/
|
*/
|
||||||
const finishBuild: () => void = async () => {
|
const finishBuild: () => void = async () => {
|
||||||
console.log("\nDone fetching everything!");
|
completed++;
|
||||||
|
// if this isn't the last feed, just return early
|
||||||
|
if (completed !== feedListLength) return;
|
||||||
|
|
||||||
|
process.stdout.write("\nDone fetching everything!\n");
|
||||||
|
|
||||||
// generate the static HTML output from our template renderer
|
// generate the static HTML output from our template renderer
|
||||||
const output = render({
|
const output = render({
|
||||||
@ -77,10 +81,10 @@ const finishBuild: () => void = async () => {
|
|||||||
|
|
||||||
// write the output to public/index.html
|
// write the output to public/index.html
|
||||||
await writeFile("./public/index.html", output);
|
await writeFile("./public/index.html", output);
|
||||||
console.log(
|
process.stdout.write(
|
||||||
`\nFinished writing to output:\n- ${feedListLength} feeds in ${benchmark(
|
`\nFinished writing to output:\n- ${feedListLength} feeds in ${benchmark(
|
||||||
initTime
|
initTime
|
||||||
)}\n- ${errors.length} errors`
|
)}\n- ${errors.length} errors\n`
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -103,7 +107,6 @@ const processFeed =
|
|||||||
}) =>
|
}) =>
|
||||||
async (response: Response): Promise<void> => {
|
async (response: Response): Promise<void> => {
|
||||||
const body = await parseFeed(response);
|
const body = await parseFeed(response);
|
||||||
completed++;
|
|
||||||
//skip to the next one if this didn't work out
|
//skip to the next one if this didn't work out
|
||||||
if (!body) return;
|
if (!body) return;
|
||||||
|
|
||||||
@ -124,20 +127,19 @@ const processFeed =
|
|||||||
});
|
});
|
||||||
|
|
||||||
contentFromAllFeeds[group].push(contents as object);
|
contentFromAllFeeds[group].push(contents as object);
|
||||||
console.log(
|
process.stdout.write(
|
||||||
`${success("Successfully fetched:")} ${feed} - ${benchmark(startTime)}`
|
`${success("Successfully fetched:")} ${feed} - ${benchmark(startTime)}\n`
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(
|
process.stdout.write(
|
||||||
`${error("Error processing:")} ${feed} - ${benchmark(
|
`${error("Error processing:")} ${feed} - ${benchmark(
|
||||||
startTime
|
startTime
|
||||||
)}\n${err}`
|
)}\n${err}\n`
|
||||||
);
|
);
|
||||||
errors.push(`Error processing: ${feed}\n\t${err}`);
|
errors.push(`Error processing: ${feed}\n\t${err}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if this is the last feed, go ahead and build the output
|
finishBuild();
|
||||||
completed === feedListLength && finishBuild();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// go through each group of feeds and process
|
// go through each group of feeds and process
|
||||||
@ -150,15 +152,16 @@ const processFeeds = () => {
|
|||||||
for (const feed of feeds) {
|
for (const feed of feeds) {
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log(`Fetching: ${feed}...`);
|
process.stdout.write(`Fetching: ${feed}...\n`);
|
||||||
|
|
||||||
fetch(feed)
|
fetch(feed)
|
||||||
.then(processFeed({ group, feed, startTime }))
|
.then(processFeed({ group, feed, startTime }))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(
|
process.stdout.write(
|
||||||
error(`Error fetching ${feed} ${benchmark(startTime)}`)
|
error(`Error fetching ${feed} ${benchmark(startTime)}\n`)
|
||||||
);
|
);
|
||||||
errors.push(`Error fetching ${feed} ${err.toString()}`);
|
errors.push(`Error fetching ${feed} ${err.toString()}\n`);
|
||||||
|
finishBuild();
|
||||||
});
|
});
|
||||||
}, (idx % (feedListLength / MAX_CONNECTIONS)) * DELAY_MS);
|
}, (idx % (feedListLength / MAX_CONNECTIONS)) * DELAY_MS);
|
||||||
idx++;
|
idx++;
|
||||||
|
Loading…
Reference in New Issue
Block a user