fix: release completed attempts before later failures
This commit is contained in:
1 parent
f0a0131aac
commit
5ed8444d5d
6 files changed
+81
-7
No files matched your search
@@ -101,6 +101,7 @@ class BatchCadRuntime:
|
||||
self._project_attempts = {}
|
||||
self._logging = None
|
||||
self._active_evidence = None
|
||||
self._active_attempts = []
|
||||
self._close_failure = None
|
||||
self._close_failure_rebuild = False
|
||||
|
||||
@@ -121,7 +122,10 @@ class BatchCadRuntime:
|
||||
|
||||
def __exit__(self, error_type, error, traceback):
|
||||
if error is not None and self._active_evidence is not None:
|
||||
attempts = [item for values in self._project_attempts.values() for item in values]
|
||||
# Only the current generation can still own an in-flight CAD write.
|
||||
# Earlier projects retain audit evidence but their closed checkpoint
|
||||
# proves that they no longer need the live CAD/desktop wait.
|
||||
attempts = list(self._active_attempts)
|
||||
try:
|
||||
self._retain_uncertain(self._active_evidence, None, attempts, error)
|
||||
except WorkerMonitorError:
|
||||
@@ -254,6 +258,7 @@ class BatchCadRuntime:
|
||||
'session_id': self.session_id, 'generation': self.generation, 'attempt_id': attempt_id,
|
||||
'evidence_root': str(root), 'project_path': str(project), 'project_closed': True,
|
||||
'worker_closed': True, 'cad_pid': self.record['cad_pid'], 'cad_guid': self.record['cad_guid']})
|
||||
self._active_attempts = []
|
||||
|
||||
def run_worker(self, command, timeout, *, abort_event=None, cooperative_abort=False):
|
||||
from .discovery_cache import project_fingerprint
|
||||
@@ -272,6 +277,7 @@ class BatchCadRuntime:
|
||||
self._save()
|
||||
generation = self.generation + (self.desktop is None)
|
||||
project, directory, expected = self._prepare_attempts(root, command, attempt_id, generation)
|
||||
self._active_attempts = list(expected)
|
||||
self._ensure_desktop(abort_event)
|
||||
before = project_fingerprint(project, self.root)
|
||||
status = internal_path(root / 'status.tsv')
|
||||
|
||||
@@ -820,10 +820,10 @@ def run_native(snapshot, report):
|
||||
refs = {record[2] for record in records}
|
||||
report['replacement_timeout'].update(
|
||||
component_count=len(current),
|
||||
components=[dict(uid=str(c.UID), refdes=str(c.Refdes),
|
||||
components=[dict(uid=_component_uid(c), refdes=str(c.Refdes),
|
||||
attributes={name: attribute_value(c, name)
|
||||
for name in ('Part Number', 'Part Name', 'Part Label', 'Value')})
|
||||
for c in current if str(c.UID) in wanted or str(c.Refdes) in refs])
|
||||
for c in current if _component_uid(c) in wanted or str(c.Refdes) in refs])
|
||||
except Exception as error:
|
||||
report['replacement_timeout']['component_readback_error'] = str(error)
|
||||
try:
|
||||
|
||||
@@ -9,8 +9,8 @@ from pathlib import Path
|
||||
import queue
|
||||
import re
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
import threading
|
||||
from uuid import uuid4
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ class WorkerMonitorError(subprocess.SubprocessError):
|
||||
pass
|
||||
|
||||
|
||||
_PROGRESS_FAILURE_LOGGED: dict[str, float] = {}
|
||||
|
||||
|
||||
class ProgressWatch:
|
||||
def __init__(self, token: str, job_id: str, idle_timeout: float, started: float) -> None:
|
||||
if idle_timeout <= 0:
|
||||
@@ -134,7 +137,12 @@ def _publish_progress(path: Path, snapshot: dict) -> None:
|
||||
except OSError as error:
|
||||
# Telemetry cannot interrupt a CAD write, but the lost state must remain diagnosable.
|
||||
import logging
|
||||
logging.getLogger(__name__).warning('worker_progress_publish_failed path=%s error=%s', path, error)
|
||||
now = time.monotonic()
|
||||
key = str(path)
|
||||
last = _PROGRESS_FAILURE_LOGGED.get(key, 0.0)
|
||||
if now - last >= 15:
|
||||
logging.getLogger(__name__).warning('worker_progress_publish_failed path=%s error=%s', path, error)
|
||||
_PROGRESS_FAILURE_LOGGED[key] = now
|
||||
|
||||
|
||||
def _decode(data: bytes) -> str:
|
||||
|
||||
Reference in new issue
Block a user