暂存一下,防止丢失
This commit is contained in:
41
pkg/queue/card_observation_series.go
Normal file
41
pkg/queue/card_observation_series.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
|
||||
cardapp "github.com/break/junhong_cmp_fiber/internal/application/cardobservation"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
)
|
||||
|
||||
// CardObservationSeriesScheduler 将固定阶梯任务提交到独立队列。
|
||||
type CardObservationSeriesScheduler struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// NewCardObservationSeriesScheduler 创建卡观测序列任务调度器。
|
||||
func NewCardObservationSeriesScheduler(client *Client) *CardObservationSeriesScheduler {
|
||||
return &CardObservationSeriesScheduler{client: client}
|
||||
}
|
||||
|
||||
// Enqueue 以稳定 series_id + attempt 任务 ID 零重试入队。
|
||||
func (s *CardObservationSeriesScheduler) Enqueue(ctx context.Context, payload cardapp.SeriesTaskPayload) error {
|
||||
taskID := "card-series-" + payload.SeriesID + "-" + strconv.Itoa(payload.Attempt)
|
||||
err := s.client.EnqueueTask(
|
||||
ctx,
|
||||
constants.TaskTypeCardObservationSeries,
|
||||
payload,
|
||||
asynq.TaskID(taskID),
|
||||
asynq.ProcessAt(payload.ScheduledAt),
|
||||
asynq.MaxRetry(0),
|
||||
)
|
||||
if errors.Is(err, asynq.ErrTaskIDConflict) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
var _ cardapp.SeriesScheduler = (*CardObservationSeriesScheduler)(nil)
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/exporter"
|
||||
"github.com/break/junhong_cmp_fiber/internal/gateway"
|
||||
"github.com/break/junhong_cmp_fiber/internal/infrastructure/integrationlog"
|
||||
notification "github.com/break/junhong_cmp_fiber/internal/infrastructure/notification"
|
||||
"github.com/break/junhong_cmp_fiber/internal/polling"
|
||||
iot_card_svc "github.com/break/junhong_cmp_fiber/internal/service/iot_card"
|
||||
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
||||
@@ -70,10 +72,12 @@ func (h *Handler) RegisterHandlers() *asynq.ServeMux {
|
||||
h.registerCommissionStatsHandlers()
|
||||
h.registerCommissionCalculationHandler()
|
||||
h.registerPollingHandlers()
|
||||
h.registerCardObservationSeriesHandler()
|
||||
h.registerPackageActivationHandlers()
|
||||
h.registerOrderExpireHandler()
|
||||
h.registerAlertCheckHandler()
|
||||
h.registerDataCleanupHandler()
|
||||
h.registerNotificationCleanupHandler()
|
||||
h.registerAutoPurchaseHandler()
|
||||
h.registerDailyTrafficFlushHandler()
|
||||
|
||||
@@ -81,6 +85,12 @@ func (h *Handler) RegisterHandlers() *asynq.ServeMux {
|
||||
return h.mux
|
||||
}
|
||||
|
||||
func (h *Handler) registerCardObservationSeriesHandler() {
|
||||
handler := task.NewCardObservationSeriesHandler(h.workerResult.Services.CardObservationSeries, h.logger)
|
||||
h.mux.HandleFunc(constants.TaskTypeCardObservationSeries, handler.Handle)
|
||||
h.logger.Info("注册卡观测事件序列任务处理器", zap.String("task_type", constants.TaskTypeCardObservationSeries))
|
||||
}
|
||||
|
||||
func (h *Handler) registerIotCardImportHandler() {
|
||||
iotCardImportHandler := task.NewIotCardImportHandler(
|
||||
h.db,
|
||||
@@ -208,13 +218,12 @@ func (h *Handler) registerCommissionCalculationHandler() {
|
||||
}
|
||||
|
||||
func (h *Handler) registerPollingHandlers() {
|
||||
integrationRepository := integrationlog.NewRepository(h.db)
|
||||
realnameHandler := task.NewPollingRealnameHandler(
|
||||
h.pollingBase, h.gatewayClient, h.workerResult.Stores.IotCard,
|
||||
h.asynqClient, h.pollingStopResumeSvc, h.workerResult.Stores.DeviceSimBinding)
|
||||
h.pollingBase, h.gatewayClient, h.workerResult.Services.CardObservation, integrationRepository)
|
||||
carrierStore := postgres.NewCarrierStore(h.db)
|
||||
carddataHandler := task.NewPollingCarddataHandler(
|
||||
h.pollingBase, h.gatewayClient, h.workerResult.Stores.IotCard,
|
||||
carrierStore, h.workerResult.Services.UsageService, h.pollingStopResumeSvc)
|
||||
h.pollingBase, h.gatewayClient, carrierStore, h.workerResult.Services.CardObservation, integrationRepository)
|
||||
packageHandler := task.NewPollingPackageHandler(
|
||||
h.pollingBase, h.workerResult.Stores.IotCard,
|
||||
h.pollingStopResumeSvc)
|
||||
@@ -222,7 +231,7 @@ func (h *Handler) registerPollingHandlers() {
|
||||
h.pollingBase, h.gatewayClient, h.workerResult.Stores.IotCard,
|
||||
h.workerResult.Stores.DeviceSimBinding, h.pollingStopResumeSvc)
|
||||
cardStatusHandler := task.NewPollingCardStatusHandler(
|
||||
h.pollingBase, h.gatewayClient, h.workerResult.Stores.IotCard, h.pollingStopResumeSvc)
|
||||
h.pollingBase, h.gatewayClient, h.workerResult.Services.CardObservation, integrationRepository)
|
||||
|
||||
h.mux.HandleFunc(constants.TaskTypePollingRealname, realnameHandler.Handle)
|
||||
h.mux.HandleFunc(constants.TaskTypePollingCarddata, carddataHandler.Handle)
|
||||
@@ -267,6 +276,13 @@ func (h *Handler) registerDataCleanupHandler() {
|
||||
h.logger.Info("注册数据清理任务处理器", zap.String("task_type", constants.TaskTypeDataCleanup))
|
||||
}
|
||||
|
||||
func (h *Handler) registerNotificationCleanupHandler() {
|
||||
cleanupService := notification.NewCleanupService(h.db, h.logger)
|
||||
cleanupHandler := task.NewNotificationCleanupHandler(cleanupService, h.logger)
|
||||
h.mux.HandleFunc(constants.TaskTypeNotificationCleanup, cleanupHandler.Handle)
|
||||
h.logger.Info("注册站内通知保留清理任务处理器", zap.String("task_type", constants.TaskTypeNotificationCleanup))
|
||||
}
|
||||
|
||||
func (h *Handler) registerAutoPurchaseHandler() {
|
||||
autoPurchaseHandler := task.NewAutoPurchaseHandler(
|
||||
h.db,
|
||||
|
||||
@@ -3,6 +3,7 @@ package queue
|
||||
import (
|
||||
"context"
|
||||
|
||||
cardObservationApp "github.com/break/junhong_cmp_fiber/internal/application/cardobservation"
|
||||
"github.com/break/junhong_cmp_fiber/internal/service/commission_calculation"
|
||||
"github.com/break/junhong_cmp_fiber/internal/service/commission_stats"
|
||||
packagepkg "github.com/break/junhong_cmp_fiber/internal/service/package"
|
||||
@@ -19,33 +20,33 @@ type OrderExpirer interface {
|
||||
|
||||
// WorkerStores Worker 侧所有 Store 的集合
|
||||
type WorkerStores struct {
|
||||
AssetOperationLog *postgres.AssetOperationLogStore
|
||||
IotCardImportTask *postgres.IotCardImportTaskStore
|
||||
IotCard *postgres.IotCardStore
|
||||
DeviceImportTask *postgres.DeviceImportTaskStore
|
||||
ExportTask *postgres.ExportTaskStore
|
||||
ExportShardTask *postgres.ExportShardTaskStore
|
||||
Device *postgres.DeviceStore
|
||||
DeviceSimBinding *postgres.DeviceSimBindingStore
|
||||
ShopSeriesCommissionStats *postgres.ShopSeriesCommissionStatsStore
|
||||
ShopPackageAllocation *postgres.ShopPackageAllocationStore
|
||||
CommissionRecord *postgres.CommissionRecordStore
|
||||
Shop *postgres.ShopStore
|
||||
ShopSeriesAllocation *postgres.ShopSeriesAllocationStore
|
||||
PackageSeries *postgres.PackageSeriesStore
|
||||
Order *postgres.OrderStore
|
||||
OrderItem *postgres.OrderItemStore
|
||||
Package *postgres.PackageStore
|
||||
PackageUsage *postgres.PackageUsageStore
|
||||
PackageUsageDailyRecord *postgres.PackageUsageDailyRecordStore
|
||||
PollingAlertRule *postgres.PollingAlertRuleStore
|
||||
PollingAlertHistory *postgres.PollingAlertHistoryStore
|
||||
DataCleanupConfig *postgres.DataCleanupConfigStore
|
||||
DataCleanupLog *postgres.DataCleanupLogStore
|
||||
AgentWallet *postgres.AgentWalletStore
|
||||
AgentWalletTransaction *postgres.AgentWalletTransactionStore
|
||||
AssetWallet *postgres.AssetWalletStore
|
||||
AssetIdentifier *postgres.AssetIdentifierStore
|
||||
AssetOperationLog *postgres.AssetOperationLogStore
|
||||
IotCardImportTask *postgres.IotCardImportTaskStore
|
||||
IotCard *postgres.IotCardStore
|
||||
DeviceImportTask *postgres.DeviceImportTaskStore
|
||||
ExportTask *postgres.ExportTaskStore
|
||||
ExportShardTask *postgres.ExportShardTaskStore
|
||||
Device *postgres.DeviceStore
|
||||
DeviceSimBinding *postgres.DeviceSimBindingStore
|
||||
ShopSeriesCommissionStats *postgres.ShopSeriesCommissionStatsStore
|
||||
ShopPackageAllocation *postgres.ShopPackageAllocationStore
|
||||
CommissionRecord *postgres.CommissionRecordStore
|
||||
Shop *postgres.ShopStore
|
||||
ShopSeriesAllocation *postgres.ShopSeriesAllocationStore
|
||||
PackageSeries *postgres.PackageSeriesStore
|
||||
Order *postgres.OrderStore
|
||||
OrderItem *postgres.OrderItemStore
|
||||
Package *postgres.PackageStore
|
||||
PackageUsage *postgres.PackageUsageStore
|
||||
PackageUsageDailyRecord *postgres.PackageUsageDailyRecordStore
|
||||
PollingAlertRule *postgres.PollingAlertRuleStore
|
||||
PollingAlertHistory *postgres.PollingAlertHistoryStore
|
||||
DataCleanupConfig *postgres.DataCleanupConfigStore
|
||||
DataCleanupLog *postgres.DataCleanupLogStore
|
||||
AgentWallet *postgres.AgentWalletStore
|
||||
AgentWalletTransaction *postgres.AgentWalletTransactionStore
|
||||
AssetWallet *postgres.AssetWalletStore
|
||||
AssetIdentifier *postgres.AssetIdentifierStore
|
||||
PersonalCustomer *postgres.PersonalCustomerStore
|
||||
PersonalCustomerPhone *postgres.PersonalCustomerPhoneStore
|
||||
OrderPackageInvalidateTask *postgres.OrderPackageInvalidateTaskStore
|
||||
@@ -53,6 +54,8 @@ type WorkerStores struct {
|
||||
|
||||
// WorkerServices Worker 侧所有 Service 的集合
|
||||
type WorkerServices struct {
|
||||
CardObservation *cardObservationApp.Service
|
||||
CardObservationSeries *cardObservationApp.SeriesAttemptService
|
||||
CommissionCalculation *commission_calculation.Service
|
||||
CommissionStats *commission_stats.Service
|
||||
UsageService *packagepkg.UsageService
|
||||
|
||||
Reference in New Issue
Block a user