Constraint: 在线热修前必须保存当前迭代分支全部有效代码进展 Confidence: medium Scope-risk: broad Directive: 后续修改需保持审计事件与业务事务边界一致 Tested: git diff --cached --check Not-tested: 未运行全量测试,提交用于切换分支前保存既有工作
38 lines
1.3 KiB
Go
38 lines
1.3 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, _ *asynq.Task) error {
|
|
ctx = auditcontext.With(ctx, auditcontext.Context{
|
|
ActorKind: constants.AuditActorSystemTask, ActorID: constants.TaskTypeNotificationCleanup,
|
|
ActorName: "站内通知清理任务", Source: constants.AuditSourceWorker,
|
|
})
|
|
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
|
|
}
|