fix: preserve live tasks during daemon recovery
This commit is contained in:
1 parent
079d7b1e28
commit
0355af7833
11 files changed
+327
-17
No files matched your search
@@ -108,6 +108,7 @@ class Settings(BaseSettings):
|
||||
OPENAI_REASONING_EFFORT: str = "high"
|
||||
ARTEMIS_CREDENTIAL_TIMEOUT_SECONDS: float = Field(default=12.0, gt=0)
|
||||
ARTEMIS_MODEL_CACHE_TTL_SECONDS: float = Field(default=10.0, ge=0)
|
||||
ARTEMIS_DAEMON_PROBE_TIMEOUT_SECONDS: float = Field(default=2.0, gt=0)
|
||||
ARTEMIS_VIDEO_TIMEOUT_SECONDS: float = Field(default=120.0, gt=0)
|
||||
ARTEMIS_VIDEO_MAX_RETRIES: int = Field(default=1, ge=0)
|
||||
ARTEMIS_VIDEO_CHUNK_SECONDS: float = Field(default=60.0, gt=0)
|
||||
|
||||
@@ -28,6 +28,9 @@ import urllib.error
|
||||
import urllib.request
|
||||
|
||||
from artemis.config.paths import ROOT_DIR
|
||||
from artemis.config.settings import settings
|
||||
from artemis.runtime.process_probe import pid_is_alive
|
||||
from artemis.runtime.server_lifecycle import is_port_in_use, read_server_info
|
||||
from artemis.utils.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
@@ -44,10 +47,11 @@ def is_standalone_forced() -> bool:
|
||||
def is_daemon_running(
|
||||
host: str = DEFAULT_DAEMON_HOST,
|
||||
port: int = DEFAULT_DAEMON_PORT,
|
||||
timeout: float = 0.3,
|
||||
timeout: float | None = None,
|
||||
) -> bool:
|
||||
"""Fast probe to check if the Artemis Daemon HTTP server is responding."""
|
||||
url = f"http://{host}:{port}/api/system/readiness"
|
||||
timeout = timeout if timeout is not None else settings.ARTEMIS_DAEMON_PROBE_TIMEOUT_SECONDS
|
||||
url = f"http://{host}:{port}/api/system/server-status"
|
||||
try:
|
||||
req = urllib.request.Request(url, headers={"User-Agent": "Artemis-Daemon-Probe"})
|
||||
with urllib.request.urlopen(req, timeout=timeout) as response:
|
||||
@@ -190,6 +194,15 @@ def ensure_daemon_running(
|
||||
if is_daemon_running(host, port):
|
||||
return True, f"http://{host}:{port}"
|
||||
|
||||
if is_port_in_use(port, host):
|
||||
# A slow/busy HTTP loop is not a stopped daemon. Only trust persisted
|
||||
# metadata belonging to a live process on the requested endpoint.
|
||||
info = read_server_info() or {}
|
||||
if info.get("port") == port and info.get("host") == host and pid_is_alive(info.get("pid")):
|
||||
return True, f"http://{host}:{port}"
|
||||
logger.warning(f"Port {host}:{port} is occupied; refusing to spawn another daemon")
|
||||
return False, None
|
||||
|
||||
# Auto-spawn Daemon in background
|
||||
spawn_daemon(host, port)
|
||||
|
||||
|
||||
Reference in new issue
Block a user