mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
fix: 加入重试机制
This commit is contained in:
parent
233fc7417c
commit
b0738c6db6
4 changed files with 39 additions and 27 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue