forked from mtusi2026/mtusi2026lab6
Реализовать наблюдаемость мессенджера и проверить её под нагрузкой
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user