mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
refactor(auth): replace NextRefreshAfter with NextRetryAfter for clarity and consistency
- Renamed field `NextRefreshAfter` to `NextRetryAfter` across `AuthManager`, `types`, and selector logic. - Updated references to ensure proper handling of retry timing logic. - Improved code readability and clarified retry behavior for different auth states.
This commit is contained in:
@@ -523,14 +523,14 @@ func (m *Manager) MarkResult(ctx context.Context, result Result) {
|
|||||||
switch statusCode {
|
switch statusCode {
|
||||||
case 401:
|
case 401:
|
||||||
auth.StatusMessage = "unauthorized"
|
auth.StatusMessage = "unauthorized"
|
||||||
auth.NextRefreshAfter = now.Add(30 * time.Minute)
|
auth.NextRetryAfter = now.Add(30 * time.Minute)
|
||||||
if result.Model != "" {
|
if result.Model != "" {
|
||||||
shouldSuspendModel = true
|
shouldSuspendModel = true
|
||||||
suspendReason = "unauthorized"
|
suspendReason = "unauthorized"
|
||||||
}
|
}
|
||||||
case 402, 403:
|
case 402, 403:
|
||||||
auth.StatusMessage = "payment_required"
|
auth.StatusMessage = "payment_required"
|
||||||
auth.NextRefreshAfter = now.Add(30 * time.Minute)
|
auth.NextRetryAfter = now.Add(30 * time.Minute)
|
||||||
if result.Model != "" {
|
if result.Model != "" {
|
||||||
shouldSuspendModel = true
|
shouldSuspendModel = true
|
||||||
suspendReason = "payment_required"
|
suspendReason = "payment_required"
|
||||||
@@ -540,14 +540,14 @@ func (m *Manager) MarkResult(ctx context.Context, result Result) {
|
|||||||
auth.Quota.Exceeded = true
|
auth.Quota.Exceeded = true
|
||||||
auth.Quota.Reason = "quota"
|
auth.Quota.Reason = "quota"
|
||||||
auth.Quota.NextRecoverAt = now.Add(30 * time.Minute)
|
auth.Quota.NextRecoverAt = now.Add(30 * time.Minute)
|
||||||
auth.NextRefreshAfter = auth.Quota.NextRecoverAt
|
auth.NextRetryAfter = auth.Quota.NextRecoverAt
|
||||||
if result.Model != "" {
|
if result.Model != "" {
|
||||||
shouldSuspendModel = true
|
shouldSuspendModel = true
|
||||||
registry.GetGlobalRegistry().SetModelQuotaExceeded(auth.ID, result.Model)
|
registry.GetGlobalRegistry().SetModelQuotaExceeded(auth.ID, result.Model)
|
||||||
}
|
}
|
||||||
case 408, 500, 502, 503, 504:
|
case 408, 500, 502, 503, 504:
|
||||||
auth.StatusMessage = "transient upstream error"
|
auth.StatusMessage = "transient upstream error"
|
||||||
auth.NextRefreshAfter = now.Add(1 * time.Minute)
|
auth.NextRetryAfter = now.Add(1 * time.Minute)
|
||||||
if result.Model != "" {
|
if result.Model != "" {
|
||||||
shouldSuspendModel = false
|
shouldSuspendModel = false
|
||||||
suspendReason = "forbidden"
|
suspendReason = "forbidden"
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func (s *RoundRobinSelector) Pick(ctx context.Context, provider, model string, o
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
for i := range auths {
|
for i := range auths {
|
||||||
candidate := auths[i]
|
candidate := auths[i]
|
||||||
if candidate.Unavailable && candidate.Quota.NextRecoverAt.After(now) {
|
if candidate.Unavailable && candidate.NextRetryAfter.After(now) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if candidate.Status == StatusDisabled || candidate.Disabled {
|
if candidate.Status == StatusDisabled || candidate.Disabled {
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ type Auth struct {
|
|||||||
LastRefreshedAt time.Time `json:"last_refreshed_at"`
|
LastRefreshedAt time.Time `json:"last_refreshed_at"`
|
||||||
// NextRefreshAfter is the earliest time a refresh should retrigger.
|
// NextRefreshAfter is the earliest time a refresh should retrigger.
|
||||||
NextRefreshAfter time.Time `json:"next_refresh_after"`
|
NextRefreshAfter time.Time `json:"next_refresh_after"`
|
||||||
|
// NextRetryAfter is the earliest time a retry should retrigger.
|
||||||
|
NextRetryAfter time.Time `json:"next_retry_after"`
|
||||||
|
|
||||||
// Runtime carries non-serialisable data used during execution (in-memory only).
|
// Runtime carries non-serialisable data used during execution (in-memory only).
|
||||||
Runtime any `json:"-"`
|
Runtime any `json:"-"`
|
||||||
|
|||||||
Reference in New Issue
Block a user