23 lines
754 B
Python
23 lines
754 B
Python
class RunLifecycleError(Exception):
|
|
pass
|
|
|
|
|
|
class RunLifecycleManager:
|
|
ARMABLE = {"STOPPED", "PAUSED_AUTH_EXPIRED"}
|
|
|
|
@classmethod
|
|
def assert_can_arm(cls, status: str):
|
|
normalized = (status or "").strip().upper()
|
|
if normalized == "RUNNING":
|
|
raise RunLifecycleError("Run already RUNNING")
|
|
if normalized == "ERROR":
|
|
raise RunLifecycleError("Run in ERROR must be reset before arming")
|
|
if normalized not in cls.ARMABLE:
|
|
raise RunLifecycleError(f"Run cannot be armed from status {normalized}")
|
|
return normalized
|
|
|
|
@classmethod
|
|
def is_armable(cls, status: str) -> bool:
|
|
normalized = (status or "").strip().upper()
|
|
return normalized in cls.ARMABLE
|