fix: 加入重试机制

This commit is contained in:
ikechan8370 2023-02-10 10:46:31 +08:00
parent 233fc7417c
commit b0738c6db6
4 changed files with 39 additions and 27 deletions

View file

@ -15,3 +15,15 @@ export async function getMessageById (id) {
let messageStr = await redis.get(`CHATGPT:MESSAGE:${id}`)
return JSON.parse(messageStr)
}
export async function tryTimes (promiseFn, maxTries = 10) {
try {
return await promiseFn()
} catch (e) {
if (maxTries > 0) {
logger.warn('Failed, retry ' + maxTries)
return tryTimes(promiseFn, maxTries - 1)
}
throw e
}
}