ЛР5: асинхронная обработка вложений (RabbitMQ + worker), transactional outbox, варианты, трек 5.1

This commit is contained in:
2026-11-20 16:57:31 +03:00
parent 276dbdad8a
commit cbaadb7636
67 changed files with 5603 additions and 20 deletions
+46
View File
@@ -0,0 +1,46 @@
"""Explicit operator replay of failed attachment jobs (lab5 grade-4).
docker compose exec -T api python -m src.replay # list failed
docker compose exec -T api python -m src.replay <job_id> # replay one
Replaying resets the job to ``pending`` and the attachment to ``queued``; the
outbox publisher republishes it. The idempotent effect key is
``(attachment_id, pipeline_version, variant)``, so replaying an already-succeeded
job can never duplicate variants.
"""
from __future__ import annotations
import argparse
import json
from . import repositories as repo
from .db import pool
def main() -> None:
parser = argparse.ArgumentParser(description="List or replay failed attachment jobs")
parser.add_argument("job_id", nargs="?", help="specific job id to replay")
args = parser.parse_args()
with pool().connection() as conn:
if args.job_id is None:
failed = repo.list_failed_jobs(conn)
print(json.dumps(
[
{
"job_id": str(row["job_id"]),
"attachment_id": str(row["attachment_id"]),
"attempt": int(row["attempt"]),
"error_code": row["last_error"],
}
for row in failed
],
ensure_ascii=False,
))
return
replayed = repo.replay_failed_jobs(conn, args.job_id)
print(json.dumps({"replayed": replayed}))
if __name__ == "__main__":
main()