mirror of
https://github.com/blw1138/cross-py-builder.git
synced 2026-09-07 21:41:09 -05:00
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:
+31
-1
@@ -46,6 +46,36 @@ def api_workers():
|
||||
return jsonify(wrk.probe_all())
|
||||
|
||||
|
||||
@app.post("/api/workers")
|
||||
def api_add_worker():
|
||||
data = request.get_json(silent=True) or {}
|
||||
spec = str(data.get("spec") or "").strip()
|
||||
host = str(data.get("host") or "").strip()
|
||||
port = data.get("port")
|
||||
try:
|
||||
if spec:
|
||||
w = wrk.parse_worker(spec)
|
||||
elif host and port:
|
||||
w = wrk.parse_worker(f"{host}:{int(port)}")
|
||||
else:
|
||||
return jsonify({"error": "Provide spec ('host:port') or host+port"}), 400
|
||||
except (ValueError, TypeError) as e:
|
||||
return jsonify({"error": str(e)}), 400
|
||||
|
||||
db.add_worker(w["host"], w["port"])
|
||||
db.set_queued_jobs_for_worker(w["url"])
|
||||
log.info("Added worker %s:%s", w["host"], w["port"])
|
||||
status = wrk.probe_worker(w["url"])
|
||||
return jsonify({"host": w["host"], "port": w["port"], "online": status is not None, "status": status}), 201
|
||||
|
||||
|
||||
@app.delete("/api/workers/<int:port>/<path:host>")
|
||||
def api_remove_worker(host, port):
|
||||
db.remove_worker(host, port)
|
||||
log.info("Removed worker %s:%s", host, port)
|
||||
return jsonify({"removed": True, "host": host, "port": port}), 200
|
||||
|
||||
|
||||
@app.get("/api/capabilities")
|
||||
def api_capabilities():
|
||||
combos = {
|
||||
@@ -161,7 +191,7 @@ def main():
|
||||
_ensure_ready()
|
||||
scheduler.start()
|
||||
_configure_logging()
|
||||
log.info("Controller listening on 0.0.0.0:%s (%d workers configured)", settings.PORT, len(settings.WORKERS))
|
||||
log.info("Controller listening on 0.0.0.0:%s (%d workers configured)", settings.PORT, len(db.list_workers()))
|
||||
if settings.DEBUG:
|
||||
app.run(host="0.0.0.0", port=settings.PORT, threaded=True)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user