feat(outbox): lab5 run outbox background publisher in api server
This commit is contained in:
@@ -13,11 +13,13 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"high-loud-apps-labs/internal/broker"
|
||||
"high-loud-apps-labs/internal/config"
|
||||
"high-loud-apps-labs/internal/domain"
|
||||
"high-loud-apps-labs/internal/httpapi"
|
||||
"high-loud-apps-labs/internal/httpapi/handler"
|
||||
"high-loud-apps-labs/internal/httpapi/middleware"
|
||||
"high-loud-apps-labs/internal/outbox"
|
||||
"high-loud-apps-labs/internal/service"
|
||||
"high-loud-apps-labs/internal/storage/postgres"
|
||||
redisstore "high-loud-apps-labs/internal/storage/redis"
|
||||
@@ -55,6 +57,17 @@ func main() {
|
||||
|
||||
store := postgres.New(pool)
|
||||
|
||||
rabbitPub, err := broker.NewRabbitPublisher(cfg.RabbitMQURL)
|
||||
if err != nil {
|
||||
log.Fatalf("rabbitmq: %v", err)
|
||||
}
|
||||
defer rabbitPub.Close()
|
||||
|
||||
outboxPub := outbox.NewPublisher(store.Outbox(), rabbitPub, 50)
|
||||
outboxCtx, outboxCancel := context.WithCancel(context.Background())
|
||||
defer outboxCancel()
|
||||
go outboxPub.Run(outboxCtx, cfg.OutboxInterval)
|
||||
|
||||
sessionRepo, cachePing, closeSession := newSessionRepo(cfg, store)
|
||||
defer closeSession()
|
||||
|
||||
@@ -145,6 +158,8 @@ func main() {
|
||||
|
||||
log.Printf("Получен сигнал завершения; readiness выключен, drain %s", cfg.ShutdownDrain)
|
||||
ready.Store(false)
|
||||
|
||||
outboxCancel()
|
||||
reconcilerCancel()
|
||||
|
||||
if cfg.ShutdownDrain > 0 {
|
||||
|
||||
Reference in New Issue
Block a user