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
+37
View File
@@ -0,0 +1,37 @@
import asyncio
import sys
from dishka import make_async_container
from messenger.attachments.domain.jobs import ReplayResult
from messenger.attachments.entrypoints.admin import rendered, run
from messenger.attachments.entrypoints.ioc import AdminProvider
from messenger.attachments.entrypoints.journal import LOG_FIELDS, subscribe_journal
from messenger.shared.application.messagebus import EventBus
from messenger.shared.config import PlatformSettings
from messenger.shared.entrypoints.ioc import PlatformProvider
from messenger.shared.infrastructure.logging import PLATFORM_FIELDS, StructlogLogger
async def serve(argv: list[str]) -> int:
platform = PlatformSettings()
logger = StructlogLogger(level=platform.log_level, allowed_fields=PLATFORM_FIELDS | LOG_FIELDS)
container = make_async_container(PlatformProvider(platform, logger), AdminProvider())
bus = await container.get(EventBus)
subscribe_journal(bus, logger)
bus.start()
try:
report = await run(container, argv)
finally:
await bus.stop()
await container.close()
sys.stdout.write(rendered(report) + "\n")
return int(report.get("result") == ReplayResult.NOT_FOUND)
def main() -> None:
sys.exit(asyncio.run(serve(sys.argv[1:])))
if __name__ == "__main__":
main()