[scraper] try to fix seeders update startup error

This commit is contained in:
TheBeastLT
2021-02-19 22:43:46 +01:00
parent e7d0c2b620
commit 236269941b

View File

@@ -10,7 +10,7 @@ const statistics = {};
function scheduleUpdateSeeders() {
console.log('Starting seeders update...')
return repository.getUpdateSeedersTorrents(50)
return getTorrents()
.then(torrents => updateCurrentSeeders(torrents))
.then(updatedTorrents => Promise.all(
updatedTorrents.map(updated => updateLimiter.schedule(() => updateTorrentSeeders(updated)))))
@@ -21,6 +21,11 @@ function scheduleUpdateSeeders() {
.then(() => scheduleUpdateSeeders());
}
async function getTorrents() {
return repository.getUpdateSeedersTorrents(50)
.catch(() => delay(5000).then(() => getTorrents()))
}
function updateStatistics(updatedTorrents) {
const totalTorrents = updatedTorrents.map(nested => nested.length).reduce((a, b) => a + b, 0);
const date = new Date().toISOString().replace(/T.*/, '');