feat(storage): lab5 implement delayed outbox and attempts tracking

This commit is contained in:
Голиков Maximillian Антон
2026-11-10 13:43:12 +03:00
parent d27a779c20
commit 8fb191fc78
3 changed files with 21 additions and 4 deletions
+17 -1
View File
@@ -57,7 +57,7 @@ func (r *OutboxRepo) ClaimBatch(ctx context.Context, limit int) ([]domain.Outbox
const q = `
WITH claimed AS (
SELECT id FROM outbox
WHERE published_at IS NULL
WHERE published_at IS NULL AND created_at <= now()
ORDER BY created_at
LIMIT $1
FOR UPDATE SKIP LOCKED
@@ -88,6 +88,22 @@ func (r *OutboxRepo) ClaimBatch(ctx context.Context, limit int) ([]domain.Outbox
return entries, mapError(rows.Err())
}
func (r *OutboxRepo) EnqueueDirect(ctx context.Context, e *domain.OutboxEntry) error {
if e.ID == "" {
e.ID = uuid.NewString()
}
const q = `
INSERT INTO outbox
(id, aggregate_type, aggregate_id, event_type, payload, attempts, created_at, published_at)
VALUES ($1::uuid, $2, $3::uuid, $4, $5::jsonb, $6, $7, $8)
`
_, err := r.pool.Exec(ctx, q,
e.ID, e.AggregateType, e.AggregateID, e.EventType,
string(e.Payload), e.Attempts, e.CreatedAt, e.PublishedAt,
)
return mapError(err)
}
func (r *OutboxRepo) MarkPublished(ctx context.Context, ids []string) error {
if len(ids) == 0 {
return nil