add retry for sending mail *sigh*

This commit is contained in:
Thomas Ruoff
2020-11-11 23:24:43 +01:00
parent 7630f56b70
commit 460510e52b
4 changed files with 53 additions and 7 deletions

20
helpers/retryWithDelay.ts Normal file
View File

@@ -0,0 +1,20 @@
import pRetry from 'p-retry'
export function retryWithDelay<T>({
run,
delay = 1000,
}: {
run: () => Promise<T>
delay?: number
}) {
return pRetry(run, {
retries: 2,
onFailedAttempt: (error) => {
console.info(
`Attempt ${error.attemptNumber}: ${error.message}. ${error.retriesLeft} retries left`
)
return new Promise((resolve) => setTimeout(resolve, delay))
},
})
}