BAI-3: harden live readiness diagnostics
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
co-authored by
multica-agent
parent
a326df2a8d
commit
777af0cb8b
@@ -51,8 +51,7 @@ class InProcessJobRunner:
|
||||
lock = self._lock(definition.lock_key)
|
||||
if not lock.acquire(blocking=False):
|
||||
return False
|
||||
self._execute_locked(job_id, idempotency_key, action, metadata, lock)
|
||||
return True
|
||||
return self._execute_locked(job_id, idempotency_key, action, metadata, lock)
|
||||
|
||||
def start_scheduler(
|
||||
self, callback: Callable[[], None], interval_seconds: float,
|
||||
@@ -105,13 +104,19 @@ class InProcessJobRunner:
|
||||
def _execute_locked(
|
||||
self, job_id: str, idempotency_key: str, action: JobAction,
|
||||
metadata: dict[str, Any] | None, lock: threading.Lock,
|
||||
) -> None:
|
||||
) -> bool:
|
||||
definition = self.registry.get(job_id)
|
||||
try:
|
||||
for attempt in range(1, definition.max_attempts + 1):
|
||||
run_id = self.repository.start(
|
||||
job_id, idempotency_key, definition.output_version, metadata
|
||||
job_id,
|
||||
idempotency_key,
|
||||
definition.output_version,
|
||||
metadata,
|
||||
definition.timeout_seconds,
|
||||
)
|
||||
if run_id is None:
|
||||
return False
|
||||
started = time.perf_counter()
|
||||
try:
|
||||
result = action()
|
||||
@@ -119,7 +124,7 @@ class InProcessJobRunner:
|
||||
raise RuntimeError(str(result.get("error") or "Job reported failure"))
|
||||
elapsed_ms = round((time.perf_counter() - started) * 1000)
|
||||
self.repository.finish(run_id, "success", elapsed_ms)
|
||||
return
|
||||
return True
|
||||
except Exception as exc:
|
||||
elapsed_ms = round((time.perf_counter() - started) * 1000)
|
||||
self.repository.finish(
|
||||
@@ -127,7 +132,8 @@ class InProcessJobRunner:
|
||||
type(exc).__name__, str(exc),
|
||||
)
|
||||
if attempt >= definition.max_attempts:
|
||||
return
|
||||
return True
|
||||
return True
|
||||
finally:
|
||||
lock.release()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user