Реализовать наблюдаемость мессенджера и проверить её под нагрузкой

This commit is contained in:
2026-11-06 18:22:53 +03:00
parent 470d9d6f1e
commit b2eca3d259
78 changed files with 10341 additions and 24 deletions
+35
View File
@@ -0,0 +1,35 @@
"""Operator-only, single-use fault barriers. Disabled in the normal Compose stack."""
import os
import time
from messenger.domain import DomainError
from messenger.pipeline import event
class PermanentFailure(Exception):
pass
def checkpoint(db, settings, job, phase):
if not settings.fault_injection:
return
with db.connection(write=True) as conn:
row = conn.execute(
"UPDATE pipeline_faults SET remaining=remaining-1 WHERE job_id=%s AND phase=%s "
"AND remaining>0 RETURNING action",
(job, phase),
).fetchone()
if row:
event(conn, job, "fault_injected", phase=phase, action=row["action"], pid=os.getpid())
if not row:
return
match row["action"]:
case "crash":
os._exit(87)
case "hang":
time.sleep(settings.job_timeout * 3)
case "transient":
raise DomainError(503, "unavailable", "Synthetic transient failure")
case "permanent":
raise PermanentFailure