feat: Add subscription upgrade group with auto downgrade

This commit is contained in:
t0ng7u
2026-02-01 02:17:17 +08:00
parent c22ca9cdb3
commit 96caec1626
8 changed files with 455 additions and 51 deletions

View File

@@ -52,6 +52,21 @@ func runSubscriptionQuotaResetOnce() {
ctx := context.Background()
totalReset := 0
totalExpired := 0
for {
n, err := model.ExpireDueSubscriptions(subscriptionResetBatchSize)
if err != nil {
logger.LogWarn(ctx, fmt.Sprintf("subscription expire task failed: %v", err))
return
}
if n == 0 {
break
}
totalExpired += n
if n < subscriptionResetBatchSize {
break
}
}
for {
n, err := model.ResetDueSubscriptions(subscriptionResetBatchSize)
if err != nil {
@@ -72,7 +87,7 @@ func runSubscriptionQuotaResetOnce() {
subscriptionCleanupLast.Store(time.Now().Unix())
}
}
if totalReset > 0 && common.DebugEnabled {
logger.LogDebug(ctx, "subscription quota reset: reset_count=%d", totalReset)
if common.DebugEnabled && (totalReset > 0 || totalExpired > 0) {
logger.LogDebug(ctx, "subscription maintenance: reset_count=%d, expired_count=%d", totalReset, totalExpired)
}
}