feat(outbox): add publisher with confirms and reconnect
This commit is contained in:
+21
-10
@@ -16,6 +16,7 @@ import (
|
||||
"mtusi2026-messenger/internal/config"
|
||||
"mtusi2026-messenger/internal/db"
|
||||
"mtusi2026-messenger/internal/logger"
|
||||
"mtusi2026-messenger/internal/outbox"
|
||||
"mtusi2026-messenger/internal/postgres"
|
||||
"mtusi2026-messenger/internal/redis"
|
||||
s3store "mtusi2026-messenger/internal/s3"
|
||||
@@ -80,17 +81,27 @@ func Run() error {
|
||||
|
||||
log.Info("s3 storage ready", "endpoint", cfg.S3.Endpoint, "bucket", s3Client.Bucket())
|
||||
|
||||
cleanupCtx, stopCleanup := context.WithCancel(context.Background())
|
||||
var cleanupWG sync.WaitGroup
|
||||
cleanupWG.Go(func() {
|
||||
runSessionCleanup(cleanupCtx, log, queries, sessionCleanupInterval)
|
||||
brokerURL, err := cfg.Broker.URL()
|
||||
if err != nil {
|
||||
log.Error("read broker url", "error", err)
|
||||
return err
|
||||
}
|
||||
publisher := outbox.NewPublisher(pool, brokerURL, log)
|
||||
|
||||
backgroundCtx, stopBackground := context.WithCancel(context.Background())
|
||||
var backgroundWG sync.WaitGroup
|
||||
backgroundWG.Go(func() {
|
||||
publisher.Run(backgroundCtx)
|
||||
})
|
||||
cleanupWG.Go(func() {
|
||||
runIdempotencyCleanup(cleanupCtx, log, queries, cfg.Server.IdempotencyTTL, idempotencyCleanupInterval)
|
||||
backgroundWG.Go(func() {
|
||||
runSessionCleanup(backgroundCtx, log, queries, sessionCleanupInterval)
|
||||
})
|
||||
cleanupWG.Go(func() {
|
||||
backgroundWG.Go(func() {
|
||||
runIdempotencyCleanup(backgroundCtx, log, queries, cfg.Server.IdempotencyTTL, idempotencyCleanupInterval)
|
||||
})
|
||||
backgroundWG.Go(func() {
|
||||
runAttachmentCleanup(
|
||||
cleanupCtx,
|
||||
backgroundCtx,
|
||||
log,
|
||||
queries,
|
||||
s3Client,
|
||||
@@ -99,8 +110,8 @@ func Run() error {
|
||||
)
|
||||
})
|
||||
defer func() {
|
||||
stopCleanup()
|
||||
cleanupWG.Wait()
|
||||
stopBackground()
|
||||
backgroundWG.Wait()
|
||||
}()
|
||||
|
||||
authService := service.NewAuthService(queries, rdb, cfg.Server.SessionTTL, log)
|
||||
|
||||
Reference in New Issue
Block a user