mirror of
https://github.com/blw1138/cross-py-builder.git
synced 2026-09-07 21:41:09 -05:00
Replace the CROSS_PY_WORKERS env list with a DB-backed worker store so agents can be added/removed (and their online status verified) from the browser. - db.py: add workers table + list_workers/add_worker/remove_worker. - workers.py: configured_workers() reads the DB instead of settings. - app.py: POST /api/workers (add, probes reachability) and DELETE /api/workers/<port>/<host>; startup log uses DB worker count. - UI: Workers card with add form, per-worker live status + OS/CPU, remove. - settings.py: drop CROSS_PY_WORKERS/_get_json_list; DB is single source. - README/DESIGN updated to describe UI-managed workers.
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
import os
|
|
|
|
|
|
def _get_bool(name, default=False):
|
|
val = os.environ.get(name)
|
|
if val is None:
|
|
return default
|
|
return val.strip().lower() in ("1", "true", "yes", "on")
|
|
|
|
|
|
def _get_int(name, default):
|
|
raw = os.environ.get(name)
|
|
if raw is None:
|
|
return default
|
|
return int(raw)
|
|
|
|
|
|
DATA_DIR = os.environ.get("CROSS_PY_DATA", os.path.join(os.path.dirname(os.path.dirname(__file__)), "data"))
|
|
DB_PATH = os.environ.get("CROSS_PY_DB", os.path.join(DATA_DIR, "jobs.db"))
|
|
BUILDS_DIR = os.environ.get("CROSS_PY_BUILDS", os.path.join(DATA_DIR, "builds"))
|
|
PORT = _get_int("CROSS_PY_PORT", 8080)
|
|
|
|
# One job at a time by default; raise to allow parallel dispatches to distinct workers.
|
|
MAX_CONCURRENT = _get_int("CROSS_PY_MAX_CONCURRENT", 1)
|
|
|
|
# Per-request timeouts (seconds) for talking to workers.
|
|
WORKER_STATUS_TIMEOUT = _get_int("CROSS_PY_WORKER_STATUS_TIMEOUT", 5)
|
|
WORKER_BUILD_TIMEOUT = _get_int("CROSS_PY_WORKER_BUILD_TIMEOUT", 3600)
|
|
|
|
# Interval (seconds) for the scheduler loop.
|
|
SCHEDULER_INTERVAL = 1.0
|
|
|
|
# Debug mode uses Flask's dev server; otherwise serve through waitress.
|
|
DEBUG = _get_bool("CROSS_PY_DEBUG", False)
|
|
|
|
|
|
def ensure_dirs():
|
|
os.makedirs(DATA_DIR, exist_ok=True)
|
|
os.makedirs(BUILDS_DIR, exist_ok=True)
|