Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
feat: retry script
Browse files Browse the repository at this point in the history
  • Loading branch information
rayriffy committed Apr 13, 2023
1 parent 18f006f commit ba2dc63
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/services/getBlurImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface BlurhashResponse {
encoded: string
}

export const getBlurImage = async (image: Asset): Promise<BlurhashResponse> => {
export const getBlurImage = async (image: Asset, attempt = 1): Promise<BlurhashResponse> => {
/*
If blurhash token is not defined, then do manually
*/
Expand Down Expand Up @@ -59,7 +59,14 @@ export const getBlurImage = async (image: Asset): Promise<BlurhashResponse> => {
encoded: `data:image/jpeg;base64,${resizedImageBuf.toString('base64')}`,
}
} catch (e) {
console.log(e)
throw 'blurhash-fail'
if (attempt > 2) {
console.log(`attempt #${attempt} failed! performing attempt #${attempt + 1} in 10 seconds`)
await new Promise(r => setTimeout(r, 10000))

return getBlurImage(image, attempt + 1)
} else {
console.log(e)
throw 'blurhash-fail'
}
}
}

0 comments on commit ba2dc63

Please sign in to comment.