mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:10:52 +00:00
fix:修复限流后未自动恢复调度的问题
This commit is contained in:
@@ -1200,6 +1200,9 @@ class ClaudeAccountService {
|
|||||||
accountData.schedulable = 'true'
|
accountData.schedulable = 'true'
|
||||||
delete accountData.rateLimitAutoStopped
|
delete accountData.rateLimitAutoStopped
|
||||||
logger.info(`✅ Auto-resuming scheduling for account ${accountId} after rate limit cleared`)
|
logger.info(`✅ Auto-resuming scheduling for account ${accountId} after rate limit cleared`)
|
||||||
|
logger.info(`📊 Account ${accountId} state after recovery: schedulable=${accountData.schedulable}`)
|
||||||
|
} else {
|
||||||
|
logger.info(`ℹ️ Account ${accountId} did not need auto-resume: autoStopped=${accountData.rateLimitAutoStopped}, schedulable=${accountData.schedulable}`)
|
||||||
}
|
}
|
||||||
await redis.setClaudeAccount(accountId, accountData)
|
await redis.setClaudeAccount(accountId, accountData)
|
||||||
|
|
||||||
@@ -1220,10 +1223,13 @@ class ClaudeAccountService {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否有限流状态
|
|
||||||
if (accountData.rateLimitStatus === 'limited' && accountData.rateLimitedAt) {
|
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
|
|
||||||
|
// 检查是否有限流状态(包括字段缺失但有自动停止标记的情况)
|
||||||
|
if (
|
||||||
|
(accountData.rateLimitStatus === 'limited' && accountData.rateLimitedAt) ||
|
||||||
|
(accountData.rateLimitAutoStopped === 'true' && accountData.rateLimitEndAt)
|
||||||
|
) {
|
||||||
// 优先使用 rateLimitEndAt(基于会话窗口)
|
// 优先使用 rateLimitEndAt(基于会话窗口)
|
||||||
if (accountData.rateLimitEndAt) {
|
if (accountData.rateLimitEndAt) {
|
||||||
const rateLimitEndAt = new Date(accountData.rateLimitEndAt)
|
const rateLimitEndAt = new Date(accountData.rateLimitEndAt)
|
||||||
@@ -1235,7 +1241,7 @@ class ClaudeAccountService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
} else {
|
} else if (accountData.rateLimitedAt) {
|
||||||
// 兼容旧数据:使用1小时限流
|
// 兼容旧数据:使用1小时限流
|
||||||
const rateLimitedAt = new Date(accountData.rateLimitedAt)
|
const rateLimitedAt = new Date(accountData.rateLimitedAt)
|
||||||
const hoursSinceRateLimit = (now - rateLimitedAt) / (1000 * 60 * 60)
|
const hoursSinceRateLimit = (now - rateLimitedAt) / (1000 * 60 * 60)
|
||||||
|
|||||||
@@ -180,11 +180,17 @@ class RateLimitCleanupService {
|
|||||||
*/
|
*/
|
||||||
async cleanupClaudeAccounts(result) {
|
async cleanupClaudeAccounts(result) {
|
||||||
try {
|
try {
|
||||||
const accounts = await claudeAccountService.getAllAccounts()
|
// 使用原始数据而不是处理过的数据,避免字段被转换
|
||||||
|
const redis = require('../models/redis')
|
||||||
|
const accounts = await redis.getAllClaudeAccounts()
|
||||||
|
|
||||||
for (const account of accounts) {
|
for (const account of accounts) {
|
||||||
// 只检查标记为限流的账号
|
// 检查所有可能处于限流状态的账号,包括自动停止的账号
|
||||||
if (account.rateLimitStatus === 'limited' || account.rateLimitedAt) {
|
if (
|
||||||
|
account.rateLimitStatus === 'limited' ||
|
||||||
|
account.rateLimitedAt ||
|
||||||
|
account.rateLimitAutoStopped === 'true'
|
||||||
|
) {
|
||||||
result.checked++
|
result.checked++
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user