lab5: исправления по ревью

Concurrent complete no longer deletes the shared verified source; admission is atomic and covers pending presign rows; relay reconciles queued jobs lost to dead-lettering; failed staging is protected until failed_retention; timestamps normalized to UTC; reprocess prefers the durable original and keeps job->attachment lock order; heartbeat errors no longer burn attempts; confirm timeout enforced; pinned images and sanitized health responses.
This commit is contained in:
Vladislav Kunetskiy
2026-10-30 23:13:44 +03:00
parent 4bdcac3dfa
commit 9d7a0acb5a
40 changed files with 592 additions and 521 deletions
+13
View File
@@ -17,6 +17,7 @@ type Repository interface {
ReleaseOutbox(ctx context.Context, id int64, reason string) error
ReapOutboxClaims(ctx context.Context) error
ReapExpiredLeases(ctx context.Context, limit int) (int, error)
ReconcileQueuedJobs(ctx context.Context, olderThan time.Duration, limit int) (int, error)
PruneOutbox(ctx context.Context, retention time.Duration) error
OldestUnpublished(ctx context.Context) (time.Time, error)
}
@@ -31,6 +32,7 @@ type Config struct {
ClaimTTL time.Duration
Batch int
ReaperInterval time.Duration
ReconcileAfter time.Duration
Retention time.Duration
}
@@ -130,6 +132,17 @@ func (r *Relay) reap(ctx context.Context) {
r.log.InfoContext(ctx, "expired job leases requeued", slog.Int("count", reaped))
}
// The broker is not the source of truth. If a delivery was dead-lettered
// or lost, the queued job has no unpublished outbox row; republish it.
if r.config.ReconcileAfter > 0 {
reconciled, err := r.repo.ReconcileQueuedJobs(ctx, r.config.ReconcileAfter, 100)
if err != nil {
r.log.WarnContext(ctx, "queued-job reconciliation failed", slog.Any("error", err))
} else if reconciled > 0 {
r.log.InfoContext(ctx, "lost queued jobs reconciled", slog.Int("count", reconciled))
}
}
if r.config.Retention > 0 {
if err := r.repo.PruneOutbox(ctx, r.config.Retention); err != nil {
r.log.WarnContext(ctx, "outbox retention failed", slog.Any("error", err))