feat: sync latest ARR implementation

This commit is contained in:
Wyndham ARR
2026-07-31 15:11:42 +08:00
parent d6f8a747fa
commit bf7939dd1a
185 changed files with 17527 additions and 2260 deletions

View File

@@ -20,6 +20,7 @@ class JobRegistration:
rule_set_sha256: str
attempt_no: int
idempotency_key: str
uploaded_filename: Optional[str] = None
@dataclass(frozen=True)
@@ -35,6 +36,12 @@ class IngestionRepository(Protocol):
def register_job(self, registration: JobRegistration) -> None:
...
def mark_running(self, job_id: str, attempt_no: int) -> None:
...
def record_failure(self, job_id: str, attempt_no: int, failure_code: str) -> None:
...
def commit_delivery(self, delivery: VerifiedDelivery) -> IngestionOutcome:
...
@@ -81,6 +88,29 @@ class InMemoryIngestionRepository:
return
self._jobs[registration.job_id] = _MemoryJob(registration=registration)
def mark_running(self, job_id: str, attempt_no: int) -> None:
with self._lock:
job = self._jobs.get(job_id)
if job is None:
raise IngestionError("JOB_NOT_FOUND", "processing job was not registered")
if attempt_no != job.registration.attempt_no:
raise IngestionError("JOB_NOT_FOUND", "processing attempt was not registered")
if job.status in {"succeeded", "failed"}:
raise IngestionError("JOB_TERMINAL", "processing job is already terminal")
job.status = "running"
def record_failure(self, job_id: str, attempt_no: int, failure_code: str) -> None:
with self._lock:
job = self._jobs.get(job_id)
if job is None:
raise IngestionError("JOB_NOT_FOUND", "processing job was not registered")
if attempt_no != job.registration.attempt_no:
raise IngestionError("JOB_NOT_FOUND", "processing attempt was not registered")
if job.status == "succeeded":
raise IngestionError("JOB_TERMINAL", "processing job is already terminal")
job.status = "failed"
job.failure_code = failure_code
def commit_delivery(self, delivery: VerifiedDelivery) -> IngestionOutcome:
envelope = delivery.envelope
with self._lock: