Сделать отправку сообщения идемпотентной по 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
+8 -1
View File
@@ -2,6 +2,7 @@ package chat
import (
"context"
"time"
"github.com/google/uuid"
)
@@ -23,7 +24,13 @@ type ChatRepository interface {
}
type MessageRepository interface {
Append(ctx context.Context, message Message) error
// AppendOnce stores message under the sender's key in its chat, unless
// the key was used there within ttl; it returns the message the key is
// bound to: the given one or the earlier one.
AppendOnce(ctx context.Context, message Message, key string, ttl time.Duration) (Message, error)
// DeleteExpiredKeys removes up to limit keys older than ttl and reports
// how many it removed.
DeleteExpiredKeys(ctx context.Context, ttl time.Duration, limit int) (int64, error)
// ListByChat returns up to limit messages ordered by (created_at, id),
// strictly after the message identified by after when set. An unknown
// chat yields an empty history.