Manage workers from the web UI, persisted in SQLite

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.
This commit is contained in:
Brett Williams
2026-08-30 23:37:31 -05:00
parent 5967b606c7
commit 18d8d2e398
10 changed files with 187 additions and 41 deletions
+33
View File
@@ -41,6 +41,39 @@ def init_db():
)
"""
)
conn.execute(
"""
CREATE TABLE IF NOT EXISTS workers (
host TEXT NOT NULL,
port INTEGER NOT NULL,
created_at TEXT NOT NULL,
PRIMARY KEY (host, port)
)
"""
)
conn.commit()
# ---- workers -------------------------------------------------------------
def list_workers():
rows = _conn().execute("SELECT host, port FROM workers ORDER BY host, port").fetchall()
return [{"host": r["host"], "port": r["port"]} for r in rows]
def add_worker(host, port):
import datetime
conn = _conn()
conn.execute(
"INSERT OR IGNORE INTO workers (host, port, created_at) VALUES (?, ?, ?)",
(host, int(port), datetime.datetime.now().isoformat()),
)
conn.commit()
def remove_worker(host, port):
conn = _conn()
conn.execute("DELETE FROM workers WHERE host = ? AND port = ?", (host, int(port)))
conn.commit()