[profile] #290 generic rel=me (links table) - extra timeout handling

This commit is contained in:
Andrea Vos 2023-01-25 22:54:12 +01:00
parent 716fa8195f
commit 0b36781037

View File

@ -4,7 +4,6 @@ const dbConnection = require('./db');
const SQL = require('sql-template-strings');
const { LinkAnalyser } = require('../src/links');
const timer = ms => new Promise( res => setTimeout(res, ms));
(async () => {
@ -17,7 +16,12 @@ const timer = ms => new Promise( res => setTimeout(res, ms));
await timer(1000);
continue;
}
const results = await Promise.all(chunk.map(({url}) => analyser.analyse(url)));
const results = await Promise.all(chunk.map(({url}) => Promise.race([
analyser.analyse(url),
new Promise((resolve, reject) =>
setTimeout(() => resolve({url: url, error: new Error('timeout')}), 12000)
),
])));
for (let result of results) {
// random TTL (0-30 days) in order to spread out the legacy load
const expireAt = parseInt(new Date() / 1000) + parseInt(30*24*60*60*Math.random());