mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
refactor: inline token refresh retry reason prefix
This commit is contained in:
@@ -12,12 +12,8 @@ import (
|
||||
"github.com/Wei-Shaw/sub2api/internal/config"
|
||||
)
|
||||
|
||||
const (
|
||||
// tokenRefreshTempUnschedDuration token 刷新重试耗尽后临时不可调度的持续时间
|
||||
tokenRefreshTempUnschedDuration = 10 * time.Minute
|
||||
|
||||
tokenRefreshRetryExhaustedReasonPrefix = "token refresh retry exhausted:"
|
||||
)
|
||||
// tokenRefreshTempUnschedDuration token 刷新重试耗尽后临时不可调度的持续时间
|
||||
const tokenRefreshTempUnschedDuration = 10 * time.Minute
|
||||
|
||||
// TokenRefreshService OAuth token自动刷新服务
|
||||
// 定期检查并刷新即将过期的token
|
||||
@@ -342,7 +338,7 @@ func (s *TokenRefreshService) refreshWithRetry(ctx context.Context, account *Acc
|
||||
|
||||
// 设置临时不可调度 10 分钟(不标记 error,保持 status=active 让下个刷新周期能继续尝试)
|
||||
until := time.Now().Add(tokenRefreshTempUnschedDuration)
|
||||
reason := fmt.Sprintf("%s %v", tokenRefreshRetryExhaustedReasonPrefix, lastErr)
|
||||
reason := fmt.Sprintf("token refresh retry exhausted: %v", lastErr)
|
||||
s.notifyAccountSchedulingBlocked(account, until, "token_refresh_retry_exhausted")
|
||||
if setErr := s.accountRepo.SetTempUnschedulable(ctx, account.ID, until, reason); setErr != nil {
|
||||
slog.Warn("token_refresh.set_temp_unschedulable_failed",
|
||||
|
||||
@@ -34,7 +34,7 @@ func (r *tokenRefreshCandidateRepo) ListOAuthRefreshCandidates(context.Context)
|
||||
refreshToken, _ := account.Credentials["refresh_token"].(string)
|
||||
inRetryCooldown := account.TempUnschedulableUntil != nil &&
|
||||
account.TempUnschedulableUntil.After(now) &&
|
||||
strings.HasPrefix(account.TempUnschedulableReason, tokenRefreshRetryExhaustedReasonPrefix)
|
||||
strings.HasPrefix(account.TempUnschedulableReason, "token refresh retry exhausted:")
|
||||
if account.Status != StatusActive ||
|
||||
account.Type != AccountTypeOAuth ||
|
||||
!isOAuthRefreshPlatform(account.Platform) ||
|
||||
@@ -119,7 +119,7 @@ func TestTokenRefreshService_ProcessRefreshUsesOAuthRefreshCandidates(t *testing
|
||||
Status: StatusActive,
|
||||
Credentials: map[string]any{"refresh_token": "refresh-token"},
|
||||
TempUnschedulableUntil: &future,
|
||||
TempUnschedulableReason: tokenRefreshRetryExhaustedReasonPrefix + " network timeout",
|
||||
TempUnschedulableReason: "token refresh retry exhausted: network timeout",
|
||||
},
|
||||
{
|
||||
ID: 5,
|
||||
@@ -183,7 +183,7 @@ func TestTokenRefreshService_RefreshFailureDoesNotCallPrivacy(t *testing.T) {
|
||||
} else {
|
||||
require.Zero(t, repo.setErrorCalls)
|
||||
require.Equal(t, 1, repo.setTempUnschedCalls)
|
||||
require.True(t, strings.HasPrefix(repo.lastTempUnschedReason, tokenRefreshRetryExhaustedReasonPrefix))
|
||||
require.True(t, strings.HasPrefix(repo.lastTempUnschedReason, "token refresh retry exhausted:"))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user