feat: Accept durable queued uploads and publish outbox jobs (U2)

Carry forward the lab4 API and storage baseline, stage verified originals in
MinIO, and atomically commit attachment, job, and outbox records before 202.
Publish identifier-only jobs with broker confirms and reclaimable outbox leases.
Clean abandoned and completed staging objects after database checks.
This commit is contained in:
Самохвалов Андрей Ремович
2026-10-02 14:35:35 +03:00
parent af7213900b
commit b23ecc111f
34 changed files with 2017 additions and 4 deletions
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
"""Exercise 202 handoff while RabbitMQ and worker are unavailable."""
import subprocess
import sys
import time
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "tests"))
from client import Client, Failure, arguments, check, run # noqa: E402
def compose(*args):
subprocess.run(
["docker", "compose", "--env-file", ".env", *args],
cwd=ROOT, check=True, stdout=subprocess.DEVNULL,
)
def ready_after_restart(client):
deadline = time.monotonic() + 90
while time.monotonic() < deadline:
try:
client.call("GET", "/health/ready", schema="Health")
return
except Failure:
time.sleep(1)
raise Failure("API did not recover after restart")
def main():
args = arguments("Lab5 durable upload handoff with stopped broker and worker")
client = Client(args.base_url, args.ca_file)
compose("stop", "worker", "publisher", "broker")
try:
alice, bob, _eve, chat = client.bootstrap()
attachment, original = client.attachment(alice, chat)
client.call("GET", f"/api/v1/attachments/{attachment['id']}/content", 409, actor=bob)
message = client.message(alice, chat, "", attachments=[attachment["id"]])["json"]
check(message["attachment_ids"] == [attachment["id"]], "queued attachment cannot be linked")
compose("up", "-d", "broker")
compose("restart", "api")
ready_after_restart(client)
check(
client.call("GET", f"/api/v1/attachments/{attachment['id']}", actor=bob, schema="Attachment")["json"]["status"] == "queued",
"accepted job disappeared before publisher restart",
)
compose("up", "-d", "publisher", "worker")
client.wait_ready(bob, attachment)
result = client.call("GET", f"/api/v1/attachments/{attachment['id']}/content", actor=bob)
check(result["bytes"] == original, "accepted original changed after recovery")
finally:
compose("up", "-d", "broker", "publisher", "worker")
print("PASS: accepted upload survived broker/API outage and reached ready")
if __name__ == "__main__":
run(main)