mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 00:53:33 +00:00
chore: 其他文件修改
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1886,11 +1886,9 @@ const redisClient = new RedisClient()
|
|||||||
// 分布式锁相关方法
|
// 分布式锁相关方法
|
||||||
redisClient.setAccountLock = async function (lockKey, lockValue, ttlMs) {
|
redisClient.setAccountLock = async function (lockKey, lockValue, ttlMs) {
|
||||||
try {
|
try {
|
||||||
// 使用SET NX EX实现原子性的锁获取
|
// 使用SET NX PX实现原子性的锁获取
|
||||||
const result = await this.client.set(lockKey, lockValue, {
|
// ioredis语法: set(key, value, 'PX', milliseconds, 'NX')
|
||||||
NX: true, // 只在键不存在时设置
|
const result = await this.client.set(lockKey, lockValue, 'PX', ttlMs, 'NX')
|
||||||
PX: ttlMs // 毫秒级过期时间
|
|
||||||
})
|
|
||||||
return result === 'OK'
|
return result === 'OK'
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Failed to acquire lock ${lockKey}:`, error)
|
logger.error(`Failed to acquire lock ${lockKey}:`, error)
|
||||||
@@ -1908,10 +1906,8 @@ redisClient.releaseAccountLock = async function (lockKey, lockValue) {
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
`
|
`
|
||||||
const result = await this.client.eval(script, {
|
// ioredis语法: eval(script, numberOfKeys, key1, key2, ..., arg1, arg2, ...)
|
||||||
keys: [lockKey],
|
const result = await this.client.eval(script, 1, lockKey, lockValue)
|
||||||
arguments: [lockValue]
|
|
||||||
})
|
|
||||||
return result === 1
|
return result === 1
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Failed to release lock ${lockKey}:`, error)
|
logger.error(`Failed to release lock ${lockKey}:`, error)
|
||||||
|
|||||||
@@ -2270,6 +2270,8 @@ class ClaudeAccountService {
|
|||||||
// 使用独立的5小时限制自动停止标记
|
// 使用独立的5小时限制自动停止标记
|
||||||
accountData.fiveHourAutoStopped = 'true'
|
accountData.fiveHourAutoStopped = 'true'
|
||||||
accountData.fiveHourStoppedAt = new Date().toISOString()
|
accountData.fiveHourStoppedAt = new Date().toISOString()
|
||||||
|
// 设置停止原因,供前端显示
|
||||||
|
accountData.stoppedReason = '5小时使用量接近限制,已自动停止调度'
|
||||||
|
|
||||||
// 发送Webhook通知
|
// 发送Webhook通知
|
||||||
try {
|
try {
|
||||||
@@ -2502,6 +2504,7 @@ class ClaudeAccountService {
|
|||||||
updatedAccountData.schedulable = 'true'
|
updatedAccountData.schedulable = 'true'
|
||||||
delete updatedAccountData.fiveHourAutoStopped
|
delete updatedAccountData.fiveHourAutoStopped
|
||||||
delete updatedAccountData.fiveHourStoppedAt
|
delete updatedAccountData.fiveHourStoppedAt
|
||||||
|
delete updatedAccountData.stoppedReason
|
||||||
|
|
||||||
// 更新会话窗口(如果有新窗口)
|
// 更新会话窗口(如果有新窗口)
|
||||||
if (newWindowStart && newWindowEnd) {
|
if (newWindowStart && newWindowEnd) {
|
||||||
|
|||||||
@@ -2616,6 +2616,10 @@ const getSchedulableReason = (account) => {
|
|||||||
if (account.stoppedReason) {
|
if (account.stoppedReason) {
|
||||||
return account.stoppedReason
|
return account.stoppedReason
|
||||||
}
|
}
|
||||||
|
// 检查5小时限制自动停止标志(备用方案)
|
||||||
|
if (account.fiveHourAutoStopped === 'true' || account.fiveHourAutoStopped === true) {
|
||||||
|
return '5小时使用量接近限制,已自动停止调度'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenAI 账户的错误状态
|
// OpenAI 账户的错误状态
|
||||||
|
|||||||
Reference in New Issue
Block a user