lab5: асинхронная очередь, worker и идемпотентный pipeline

API принимает 202 после durable staging и TX intent (job+outbox); отдельные relay и worker публикуют/обрабатывают задания с publisher confirm, lease, retry/backoff, DLQ и replay. Добавлены версии pipeline, варианты thumbnail/crop/optimized, presign в verified staging, status-aware sweeper и admission control.
This commit is contained in:
Vladislav Kunetskiy
2026-10-30 22:36:52 +03:00
parent 6c5ba026f1
commit 4bdcac3dfa
95 changed files with 8466 additions and 764 deletions
+18 -1
View File
@@ -11,6 +11,11 @@ import (
type Repository interface {
IsChatMember(ctx context.Context, chatID, userID uuid.UUID) (bool, error)
// Replay returns the stored message for a live Idempotency-Key. It must be
// checked before attachment-state validation: a message that was accepted
// while the attachment was queued keeps replaying as 201 even after the
// attachment later fails.
Replay(ctx context.Context, draft domain.MessageDraft) (domain.Message, bool, error)
Create(ctx context.Context, draft domain.MessageDraft) (domain.Message, error)
ListVisible(
ctx context.Context,
@@ -50,6 +55,15 @@ func (s *Service) Send(ctx context.Context, draft domain.MessageDraft) (domain.M
return domain.Message{}, fmt.Errorf("%w: chat is not visible", domain.ErrNotFound)
}
replayed, found, err := s.messages.Replay(ctx, draft)
if err != nil {
return domain.Message{}, fmt.Errorf("replay message: %w", err)
}
if found {
return replayed, nil
}
if len(draft.AttachmentIDs) > 0 {
if s.attachments == nil {
return domain.Message{}, fmt.Errorf("attachment checker is not configured: %w", domain.ErrUnavailable)
@@ -65,7 +79,10 @@ func (s *Service) Send(ctx context.Context, draft domain.MessageDraft) (domain.M
}
for _, state := range states {
if state.Status != domain.AttachmentReady {
switch state.Status {
case domain.AttachmentQueued, domain.AttachmentProcessing, domain.AttachmentReady:
// Accepted work is linkable by contract.
default:
return domain.Message{}, fmt.Errorf(
"%w: attachment %s is %s",
domain.ErrConflict, state.ID, state.Status,