Files
hi-server/queue/handler/routes.go
T
shanshanzhong147 af22430101
Build docker and publish / build (20.15.1) (pull_request) Failing after 8m15s
fix: 修复订单 claim 机制状态冲突与 stuck 订单恢复
- 将 OrderStatusClaimed 从 4 改为 6,与 OrderStatusFailed(4) 区分
- releaseClaim 改为返回 error,失败时不再静默吞掉
- claimAndGetOrder 对 status=claimed 返回可重试错误而非静默跳过
- ProcessTask 区分 claimed stuck 错误(触发重试)和其他非 paid 状态(跳过)
- finalizeCouponAndOrder 使用直接 DB 更新 claimed→finished,绕过
  UpdateOrderStatus 的 status<target 守卫(6 > 5 无法通过该条件)
  并显式删除 Redis 缓存避免缓存脏读
- 新增 StuckOrderRecoveryLogic:每 10 分钟扫描超时 claimed 订单,
  重置为 paid 并重新入队激活任务

Co-authored-by: multica-agent <github@multica.ai>
2026-05-24 23:42:37 -07:00

55 lines
2.2 KiB
Go

package handler
import (
"github.com/hibiken/asynq"
"github.com/perfect-panel/server/internal/svc"
iapLogic "github.com/perfect-panel/server/queue/logic/iap"
orderLogic "github.com/perfect-panel/server/queue/logic/order"
smslogic "github.com/perfect-panel/server/queue/logic/sms"
"github.com/perfect-panel/server/queue/logic/subscription"
"github.com/perfect-panel/server/queue/logic/task"
"github.com/perfect-panel/server/queue/logic/traffic"
"github.com/perfect-panel/server/queue/types"
emailLogic "github.com/perfect-panel/server/queue/logic/email"
)
func RegisterHandlers(mux *asynq.ServeMux, serverCtx *svc.ServiceContext) {
// Send email task
mux.Handle(types.ForthwithSendEmail, emailLogic.NewSendEmailLogic(serverCtx))
// Send sms task
mux.Handle(types.ForthwithSendSms, smslogic.NewSendSmsLogic(serverCtx))
// Defer close order task
mux.Handle(types.DeferCloseOrder, orderLogic.NewDeferCloseOrderLogic(serverCtx))
// Forthwith activate order task
mux.Handle(types.ForthwithActivateOrder, orderLogic.NewActivateOrderLogic(serverCtx))
// Forthwith traffic statistics
mux.Handle(types.ForthwithTrafficStatistics, traffic.NewTrafficStatisticsLogic(serverCtx))
// Schedule check subscription
mux.Handle(types.SchedulerCheckSubscription, subscription.NewCheckSubscriptionLogic(serverCtx))
// Schedule total server data
mux.Handle(types.SchedulerTotalServerData, traffic.NewServerDataLogic(serverCtx))
// Schedule reset traffic
mux.Handle(types.SchedulerResetTraffic, traffic.NewResetTrafficLogic(serverCtx))
// ScheduledBatchSendEmail
mux.Handle(types.ScheduledBatchSendEmail, emailLogic.NewBatchEmailLogic(serverCtx))
// ScheduledTrafficStat
mux.Handle(types.SchedulerTrafficStat, traffic.NewStatLogic(serverCtx))
// ForthwithQuotaTask
mux.Handle(types.ForthwithQuotaTask, task.NewQuotaTaskLogic(serverCtx))
// Apple IAP 对账(第二层:5min 扫描 + 第三层:日终全量)
mux.Handle(types.SchedulerIAPReconcile, iapLogic.NewReconcileLogic(serverCtx))
mux.Handle(types.SchedulerIAPDailyReconcile, iapLogic.NewDailyReconcileLogic(serverCtx))
// Stuck order recovery: reset claimed orders that timed out back to paid
mux.Handle(types.SchedulerStuckOrderRecovery, orderLogic.NewStuckOrderRecoveryLogic(serverCtx))
}