feat: openai账号401自动停止调度

This commit is contained in:
shaw
2025-09-24 11:35:48 +08:00
parent 00faa21e4b
commit f56d1edce0
5 changed files with 364 additions and 14 deletions

View File

@@ -356,7 +356,12 @@ class UnifiedOpenAIScheduler {
try {
if (accountType === 'openai') {
const account = await openaiAccountService.getAccount(accountId)
if (!account || !account.isActive || account.status === 'error') {
if (
!account ||
!account.isActive ||
account.status === 'error' ||
account.status === 'unauthorized'
) {
return false
}
// 检查是否可调度
@@ -370,7 +375,8 @@ class UnifiedOpenAIScheduler {
if (
!account ||
(account.isActive !== true && account.isActive !== 'true') ||
account.status === 'error'
account.status === 'error' ||
account.status === 'unauthorized'
) {
return false
}
@@ -500,6 +506,39 @@ class UnifiedOpenAIScheduler {
}
}
// 🚫 标记账户为未授权状态
async markAccountUnauthorized(
accountId,
accountType,
sessionHash = null,
reason = 'OpenAI账号认证失败401错误'
) {
try {
if (accountType === 'openai') {
await openaiAccountService.markAccountUnauthorized(accountId, reason)
} else if (accountType === 'openai-responses') {
await openaiResponsesAccountService.markAccountUnauthorized(accountId, reason)
} else {
logger.warn(
`⚠️ Unsupported account type ${accountType} when marking unauthorized for account ${accountId}`
)
return { success: false }
}
if (sessionHash) {
await this._deleteSessionMapping(sessionHash)
}
return { success: true }
} catch (error) {
logger.error(
`❌ Failed to mark account as unauthorized: ${accountId} (${accountType})`,
error
)
throw error
}
}
// ✅ 移除账户的限流状态
async removeAccountRateLimit(accountId, accountType) {
try {