Add the failed registry, an explicit replay and failed staging retention

python -m messenger.admin is a new process assembly over the attachments
zone with only a database: "failed" lists failed jobs (served by the new
partial index jobs_failed_idx), "replay --attachment-id" moves a failed
attachment back to queued with the same job_id, attempt 1 and a fresh
outbox row, writing a replayed event with the operator. A ready, queued
or processing attachment is a noop (replay_noop event), a failed one
whose staging is already gone is expired. Every request is audited.

The relay now also removes the staging object of a failed attachment
once STAGING_RETENTION_SECONDS have passed since it failed; replay and
the cleanup take the same row lock.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Artyom
2026-10-29 03:12:19 +03:00
co-authored by Claude Opus 5.5
parent ecb4827e75
commit b568fcf9c9
18 changed files with 365 additions and 24 deletions
@@ -11,6 +11,7 @@ from messenger.attachments.application.commands import (
ProcessJob,
PublishOutbox,
RecoverExpiredLeases,
ReplayAttachment,
SweepAbandonedUploads,
UploadAttachment,
)
@@ -24,6 +25,7 @@ from messenger.attachments.application.pipeline import (
ProcessJobHandler,
PublishOutboxHandler,
RecoverExpiredLeasesHandler,
ReplayAttachmentHandler,
)
from messenger.attachments.application.ports import (
AttachmentDirectory,
@@ -245,3 +247,22 @@ class RelayProvider(Provider):
CleanStaging: CleanStagingHandler(uow, storage),
}
return AttachmentsCommandBus(handlers, uow, publisher)
class AdminProvider(Provider):
@provide(scope=Scope.APP)
def directory(self, database: Database) -> AttachmentDirectory:
return PostgresAttachmentDirectory(database)
@provide(scope=Scope.REQUEST)
def unit_of_work(self, database: Database) -> AttachmentsUnitOfWork:
return PostgresAttachmentsUnitOfWork(database)
@provide(scope=Scope.REQUEST)
def command_bus(
self, uow: AttachmentsUnitOfWork, publisher: EventPublisher
) -> AttachmentsCommandBus:
handlers: dict[type[Command], CommandHandler] = {
ReplayAttachment: ReplayAttachmentHandler(uow)
}
return AttachmentsCommandBus(handlers, uow, publisher)