mirror of
https://github.com/blw1138/cross-py-builder.git
synced 2026-09-07 21:41:09 -05:00
Fix worker removal and improve web UI defaults
- Parse optional http:// scheme prefix on worker specs so a scheme-typed IP is stored cleanly and its remove button works. - Delete workers by their stored DB host/port instead of re-parsing the rendered URL, and surface add/remove errors in the UI. - Default new builds to git URL instead of zip upload. - Show worker hostname/IP from agent status in the address column. - Always include DB host/port in worker API output.
This commit is contained in:
+16
-4
@@ -4,8 +4,16 @@ import requests
|
||||
|
||||
|
||||
def parse_worker(spec):
|
||||
"""'host:port' -> {'url': 'http://host:port', 'host': host, 'port': port}."""
|
||||
host, _, port = spec.strip().rpartition(":")
|
||||
"""'host:port' -> {'url': 'http://host:port', 'host': host, 'port': port}.
|
||||
|
||||
Tolerates an optional http:// or https:// scheme prefix.
|
||||
"""
|
||||
s = spec.strip()
|
||||
for scheme in ("http://", "https://"):
|
||||
if s.lower().startswith(scheme):
|
||||
s = s[len(scheme):]
|
||||
break
|
||||
host, _, port = s.rpartition(":")
|
||||
if not host or not port.isdigit():
|
||||
raise ValueError(f"Invalid worker spec: {spec!r} (expected host:port)")
|
||||
return {"url": f"http://{host}:{port}", "host": host, "port": int(port)}
|
||||
@@ -22,7 +30,7 @@ def configured_workers():
|
||||
return out
|
||||
|
||||
|
||||
def probe_worker(url, timeout=None):
|
||||
def probe_worker(url, host=None, port=None, timeout=None):
|
||||
"""Return a normalized worker status dict, or None if unreachable."""
|
||||
timeout = timeout or settings.WORKER_STATUS_TIMEOUT
|
||||
try:
|
||||
@@ -34,13 +42,17 @@ def probe_worker(url, timeout=None):
|
||||
|
||||
info["url"] = url
|
||||
info["online"] = True
|
||||
if host is not None:
|
||||
info["host"] = host
|
||||
if port is not None:
|
||||
info["port"] = port
|
||||
return info
|
||||
|
||||
|
||||
def probe_all():
|
||||
workers = []
|
||||
for w in configured_workers():
|
||||
status = probe_worker(w["url"])
|
||||
status = probe_worker(w["url"], host=w["host"], port=w["port"])
|
||||
if status:
|
||||
workers.append(status)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user