Files
junhong_cmp_fiber/internal/task/notification_cleanup.go
break 88cc5e96ec
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m32s
暂存
2026-08-06 09:35:00 +08:00

39 lines
1.4 KiB
Go

package task
import (
"context"
"github.com/hibiken/asynq"
"go.uber.org/zap"
notificationinfra "github.com/break/junhong_cmp_fiber/internal/infrastructure/notification"
"github.com/break/junhong_cmp_fiber/pkg/auditcontext"
"github.com/break/junhong_cmp_fiber/pkg/constants"
)
// NotificationCleanupHandler 处理低峰通知保留清理任务。
type NotificationCleanupHandler struct {
service *notificationinfra.CleanupService
logger *zap.Logger
}
// NewNotificationCleanupHandler 创建通知保留清理任务处理器。
func NewNotificationCleanupHandler(service *notificationinfra.CleanupService, logger *zap.Logger) *NotificationCleanupHandler {
return &NotificationCleanupHandler{service: service, logger: logger}
}
// Handle 执行有界、可重入的通知分批清理。
func (h *NotificationCleanupHandler) Handle(ctx context.Context, task *asynq.Task) error {
ctx = auditcontext.With(ctx, auditcontext.Context{
ActorKind: constants.AuditActorSystemTask, ActorID: constants.TaskTypeNotificationCleanup,
ActorName: "站内通知清理任务", Source: constants.AuditSourceWorker,
CorrelationID: task.ResultWriter().TaskID(),
})
h.logger.Info("开始执行站内通知保留清理")
if err := h.service.Run(ctx); err != nil {
h.logger.Error("站内通知保留清理失败", zap.String("failure_category", "database"), zap.Error(err))
return err
}
return nil
}