mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +01:00
add retry for sending mail *sigh*
This commit is contained in:
20
helpers/retryWithDelay.ts
Normal file
20
helpers/retryWithDelay.ts
Normal 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))
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user