修改403逻辑: 先临时冷却,再根据连续次数决定是否判坏号
This commit is contained in:
@@ -20,6 +20,7 @@ type rateLimitAccountRepoStub struct {
|
||||
updateCredentialsCalls int
|
||||
lastCredentials map[string]any
|
||||
lastErrorMsg string
|
||||
lastTempReason string
|
||||
}
|
||||
|
||||
func (r *rateLimitAccountRepoStub) SetError(ctx context.Context, id int64, errorMsg string) error {
|
||||
@@ -30,6 +31,7 @@ func (r *rateLimitAccountRepoStub) SetError(ctx context.Context, id int64, error
|
||||
|
||||
func (r *rateLimitAccountRepoStub) SetTempUnschedulable(ctx context.Context, id int64, until time.Time, reason string) error {
|
||||
r.tempCalls++
|
||||
r.lastTempReason = reason
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -44,6 +46,29 @@ type tokenCacheInvalidatorRecorder struct {
|
||||
err error
|
||||
}
|
||||
|
||||
type openAI403CounterCacheStub struct {
|
||||
counts []int64
|
||||
resetCalls []int64
|
||||
err error
|
||||
}
|
||||
|
||||
func (s *openAI403CounterCacheStub) IncrementOpenAI403Count(_ context.Context, _ int64, _ int) (int64, error) {
|
||||
if s.err != nil {
|
||||
return 0, s.err
|
||||
}
|
||||
if len(s.counts) == 0 {
|
||||
return 1, nil
|
||||
}
|
||||
count := s.counts[0]
|
||||
s.counts = s.counts[1:]
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (s *openAI403CounterCacheStub) ResetOpenAI403Count(_ context.Context, accountID int64) error {
|
||||
s.resetCalls = append(s.resetCalls, accountID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *tokenCacheInvalidatorRecorder) InvalidateToken(ctx context.Context, account *Account) error {
|
||||
r.accounts = append(r.accounts, account)
|
||||
return r.err
|
||||
|
||||
Reference in New Issue
Block a user