feat: add job outbox, relay, leases and image variants to the pipeline

Move publishing out of the upload path: a relay process publishes queued
jobs with confirms. Add lease and attempt fencing, backoff with jitter, a
per-job render process with CPU and memory limits, crop and optimized
variants, the failed registry with audited replay, and staging cleanup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 15:36:15 +03:00
co-authored by Claude Opus 5.5
parent 99a222eee2
commit e2a6427c24
102 changed files with 9499 additions and 1916 deletions
+39 -6
View File
@@ -232,6 +232,7 @@ async def run(
interval_seconds=cleaner.interval_seconds,
pending_grace_seconds=cleaner.pending_grace_seconds,
batch_size=cleaner.batch_size,
staging_retention_seconds=cleaner.staging_retention_seconds,
live_upload_bound_seconds=bound,
once=mode == MODE_ONCE,
reconcile_interval_seconds=reconciler.interval_seconds,
@@ -295,12 +296,19 @@ async def _serve(
batch_size=cleaner.batch_size,
stop=stop,
)
staging = await _clean_staging_once(
cleanup,
retention_seconds=cleaner.staging_retention_seconds,
batch_size=cleaner.batch_size,
stop=stop,
)
if once:
if result is None or result.interrupted_by not in (
None,
INTERRUPTED_BY_STOP,
):
return EXIT_PASS_FAILED
for done in (result, staging):
if done is None or done.interrupted_by not in (
None,
INTERRUPTED_BY_STOP,
):
return EXIT_PASS_FAILED
return EXIT_OK
pause = cleaner.interval_seconds
if next_reconcile is not None and not stop.is_set():
@@ -348,6 +356,26 @@ async def _clean_once(
return None
async def _clean_staging_once(
service: AttachmentCleanupService,
*,
retention_seconds: int,
batch_size: int,
stop: asyncio.Event,
) -> dataclasses.StagingCleanupPassDTO | None:
"""Проход очистки staging; `None` — непредвиденная ошибка, как у уборки."""
retention_before = utcnow() - timedelta(seconds=retention_seconds)
try:
return await service.clean_staging(
retention_before=retention_before,
batch_size=batch_size,
stop_requested=stop.is_set,
)
except Exception as e:
logger.error("Staging cleanup pass failed", exc_info=e)
return None
async def _reconcile_once(
service: AttachmentReconcileService,
*,
@@ -360,12 +388,17 @@ async def _reconcile_once(
) -> dataclasses.ReconcilePassDTO | None:
"""Проход сверки; `None` — непредвиденная ошибка: `error` с
traceback, сервис живёт до следующей плановой сверки."""
older_than = utcnow() - timedelta(
now = utcnow()
older_than = now - timedelta(
seconds=settings.cleaner.pending_grace_seconds,
)
staging_older_than = now - timedelta(
seconds=settings.cleaner.staging_retention_seconds,
)
try:
return await service.reconcile(
older_than=older_than,
staging_older_than=staging_older_than,
apply=apply,
max_changes=max_changes,
page_size=settings.reconciler.page_size,