Сделать отправку сообщения идемпотентной по Idempotency-Key с общей таблицей ключей и их чисткой

This commit is contained in:
2026-11-02 17:11:04 +03:00
parent 7fa8881eb3
commit 951fd0d517
19 changed files with 856 additions and 40 deletions
+10
View File
@@ -9,9 +9,12 @@ import (
"os"
"os/signal"
"runtime"
"sync"
"syscall"
"time"
"messenger/internal/app"
"messenger/internal/chat"
"messenger/internal/platform/config"
"messenger/internal/platform/ident"
"messenger/internal/platform/postgres"
@@ -19,6 +22,9 @@ import (
"messenger/internal/server"
)
// keyCleanupEvery is how often each replica deletes expired Idempotency-Keys.
const keyCleanupEvery = 10 * time.Minute
func main() {
cfg, err := config.Load(os.LookupEnv)
if err != nil {
@@ -71,6 +77,10 @@ func run(ctx context.Context, log *slog.Logger, cfg config.Config, alias string)
InstanceID: alias,
IdempotencyTTL: cfg.IdempotencyTTL,
})
var background sync.WaitGroup
defer background.Wait() // before the deferred pool.Close
background.Go(func() { chat.RunKeyCleanup(ctx, log, a.Chats, keyCleanupEvery) })
return server.Run(ctx, log, ln, a.Engine, a.Health, cfg.DrainDelay, cfg.ShutdownTimeout)
}