refactor(admin): decouple system cleanup with event bus and enforce single owner principle

This commit is contained in:
ryan
2026-09-03 08:50:37 +08:00
parent 1e19d8114a
commit 6b28adfacf
14 changed files with 419 additions and 50 deletions
@@ -21,6 +21,7 @@ import (
"context"
"embed"
"reflect"
"time"
"github.com/gin-gonic/gin"
)
@@ -204,6 +205,13 @@ func (p *Plugin) Apply(ctx *core.Context) error {
return nil
})
// 8.1 Register system cleanup event listener
ctx.Events().On(contracts.EventTopicSystemCleanup, func(c context.Context, _ contracts.SystemCleanupEvent) error {
const defaultPushHistoryRetention = 30 * 24 * time.Hour
_, err := service.CleanupPushHistories(c, defaultPushHistoryRetention)
return err
})
// 9. Register built-in domain events and provide PushRegistry
service.RegisterCustomEvents()
core.Provide[contracts.PushRegistry](ctx, service.PushRegistryAdapter{})