Skip to content

Commit

Permalink
Log tracker errors per torrent
Browse files Browse the repository at this point in the history
  • Loading branch information
phillmac committed May 27, 2021
1 parent 67d791c commit 59ebb8f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/scrape-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ module.exports = function (redisClient, lock, debugVerbose = false) {
return new Promise((resolve, reject) => {
console.info(`Scraping trackers for ${infoHash}`)
const results = {}
const errors = []
let trackersPending = announce.length

const trackerClient = new Client({
Expand All @@ -84,11 +85,13 @@ module.exports = function (redisClient, lock, debugVerbose = false) {
const resultsComplete = () => {
trackersPending -= 1
if (trackersPending <= 0) {
logErrors(infoHash, errors)
resolve(results)
}
}

trackerClient.on('warning', (err) => {
errors.push(err)
console.warn(err)
resultsComplete()
})
Expand All @@ -107,7 +110,9 @@ module.exports = function (redisClient, lock, debugVerbose = false) {
trackerClient.scrape()
})
}

function logErrors (infoHash, errors) {
return redisClient.hsetAsync('torrent_errors', infoHash, JSON.stringify(errors))
}
async function appendTrackerErrors (trackers) {
const unlock = await lock('eLock')
for (const t of trackers) {
Expand Down

0 comments on commit 59ebb8f

Please sign in to comment.