Skip to content

Commit

Permalink
Merge pull request #386 from Klimatbyran/fix/backoffDelay
Browse files Browse the repository at this point in the history
fix: delay when parsing pdf with nlm-ingestor
  • Loading branch information
irony authored Dec 4, 2024
2 parents ce0392d + 1bd048d commit 83e998d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/discord/commands/pdfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,20 @@ export default {
})

thread.send(`PDF i kö: ${url}`)
nlmParsePDF.queue.add('download ' + url.slice(-20), {
url,
threadId: thread.id,
})
nlmParsePDF.queue.add(
'download ' + url.slice(-20),
{
url,
threadId: thread.id,
},
{
backoff: {
type: 'fixed',
delay: 60_000,
},
attempts: 10,
}
)
})
} catch (error) {
console.error('Pdfs: error', error)
Expand Down
11 changes: 11 additions & 0 deletions src/workers/nlmParsePDF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ const nlmParsePDF = new DiscordWorker(
let json
try {
json = await extractJsonFromPdf(pdf)
} catch (err) {
if (job.attemptsMade < (job.opts?.attempts || 10)) {
job.editMessage(
`❌ Fel vid tolkning av PDF: ${err.message}. Försöker igen om en stund...`
)
} else {
job.editMessage(
`❌ Fel vid tolkning av PDF: ${err.message}. Ger upp...`
)
}
throw new Error('Failed to parse PDF, retrying in one minute...')
} finally {
clearInterval(interval)
}
Expand Down

0 comments on commit 83e998d

Please sign in to comment.