"...internal/handler/git@web.lueluesay.top:chenxi/sub2api.git" did not exist on "0fba1901c8d5a494e9501c4e96a17dfc537b6bdf"
Commit f648b8e0 authored by QTom's avatar QTom
Browse files

feat: increment RPM counter before request forwarding

parent 678c3ae1
......@@ -366,6 +366,13 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
// 账号槽位/等待计数需要在超时或断开时安全回收
accountReleaseFunc = wrapReleaseOnDone(c.Request.Context(), accountReleaseFunc)
// RPM 计数递增(调度成功后、Forward 前)
if account.IsAnthropicOAuthOrSetupToken() && account.GetBaseRPM() > 0 {
if h.gatewayService.IncrementAccountRPM(c.Request.Context(), account.ID) != nil {
// 失败开放:不阻塞请求
}
}
// 转发请求 - 根据账号平台分流
var result *service.ForwardResult
requestCtx := c.Request.Context()
......@@ -549,6 +556,13 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
// 账号槽位/等待计数需要在超时或断开时安全回收
accountReleaseFunc = wrapReleaseOnDone(c.Request.Context(), accountReleaseFunc)
// RPM 计数递增(调度成功后、Forward 前)
if account.IsAnthropicOAuthOrSetupToken() && account.GetBaseRPM() > 0 {
if h.gatewayService.IncrementAccountRPM(c.Request.Context(), account.ID) != nil {
// 失败开放:不阻塞请求
}
}
// 转发请求 - 根据账号平台分流
var result *service.ForwardResult
requestCtx := c.Request.Context()
......
......@@ -2241,6 +2241,15 @@ func (s *GatewayService) isAccountSchedulableForRPM(ctx context.Context, account
return true
}
// IncrementAccountRPM increments the RPM counter for the given account.
func (s *GatewayService) IncrementAccountRPM(ctx context.Context, accountID int64) error {
if s.rpmCache == nil {
return nil
}
_, err := s.rpmCache.IncrementRPM(ctx, accountID)
return err
}
// checkAndRegisterSession 检查并注册会话,用于会话数量限制
// 仅适用于 Anthropic OAuth/SetupToken 账号
// sessionID: 会话标识符(使用粘性会话的 hash)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment