fix: enforce pipeline lifecycle limits

This commit is contained in:
2026-10-30 13:45:49 +03:00
parent 3835106125
commit aa5d6a6e16
20 changed files with 770 additions and 308 deletions
+23
View File
@@ -111,3 +111,26 @@ func (s *Store) RecoverExpiredOutboxEvents(ctx context.Context, now time.Time) (
}
return int(result.RowsAffected()), nil
}
func (s *Store) DeletePublishedOutboxEvents(ctx context.Context, publishedBefore time.Time, limit int) (int, error) {
if publishedBefore.IsZero() || limit < 1 || limit > 1000 {
return 0, model.ErrInvalidInput
}
const query = `
WITH candidates AS (
SELECT id
FROM outbox_events
WHERE published_at < $1
ORDER BY published_at, id
LIMIT $2
FOR UPDATE SKIP LOCKED
)
DELETE FROM outbox_events event
USING candidates
WHERE event.id = candidates.id`
result, err := s.pool.Exec(ctx, query, publishedBefore.UTC(), limit)
if err != nil {
return 0, fmt.Errorf("delete published outbox events: %w", err)
}
return int(result.RowsAffected()), nil
}