feat(tower): routines api save build push
This commit is contained in:
+32
-1
@@ -90,6 +90,8 @@ class H(BaseHTTPRequestHandler):
|
||||
st = C.box_state_load()
|
||||
delta = C.compute_delta(C.staging_files(), st.get("have", []))
|
||||
self._json({"box": st, "delta": delta, "staging_count": len(C.staging_files())}); return
|
||||
if path == "/api/routines":
|
||||
self._json({"routines": C.routines_load()}); return
|
||||
self.send_error(404)
|
||||
|
||||
# --- POST ---
|
||||
@@ -109,7 +111,10 @@ class H(BaseHTTPRequestHandler):
|
||||
delta = C.compute_delta(C.staging_files(), have)
|
||||
print(f"register {ip} id={body.get('id')} have={len(have)} push={len(delta)}", flush=True)
|
||||
started = C.try_push(ip, delta)
|
||||
self._json({"queued": len(delta), "started": started}); return
|
||||
r_delta = C.compute_routines_delta(have)
|
||||
if r_delta:
|
||||
C.try_push(ip, r_delta, subdir="routines")
|
||||
self._json({"queued": len(delta) + len(r_delta), "started": started}); return
|
||||
if not self._auth_ok():
|
||||
return
|
||||
if path == "/api/feeds":
|
||||
@@ -165,6 +170,32 @@ class H(BaseHTTPRequestHandler):
|
||||
delta = C.compute_delta(C.staging_files(), st.get("have", []))
|
||||
started = C.try_push(ip, delta)
|
||||
self._json({"ip": ip, "delta": len(delta), "started": started}); return
|
||||
if path == "/api/routines":
|
||||
try:
|
||||
b = json.loads(self._body() or b"{}")
|
||||
routines = b["routines"]
|
||||
assert isinstance(routines, list)
|
||||
except Exception as e:
|
||||
self._json({"error": str(e)}, 400); return
|
||||
C.routines_save(routines)
|
||||
n_steps = sum(len(r.get("steps", [])) for r in routines)
|
||||
def work():
|
||||
try:
|
||||
res = C.build_routine_manifest()
|
||||
print("routines built", res["generated"], "gen",
|
||||
res["skipped"], "cached", flush=True)
|
||||
except Exception as e:
|
||||
print("routines build fail", e, flush=True)
|
||||
threading.Thread(target=work, daemon=True).start()
|
||||
self._json({"queued": n_steps}, 202); return
|
||||
if path == "/api/routines/push":
|
||||
st = C.box_state_load()
|
||||
ip = st.get("ip")
|
||||
if not ip:
|
||||
self._json({"error": "box never registered"}, 409); return
|
||||
delta = C.compute_routines_delta(st.get("have", []))
|
||||
started = C.try_push(ip, delta, subdir="routines")
|
||||
self._json({"ip": ip, "delta": len(delta), "started": started}); return
|
||||
self.send_error(404)
|
||||
|
||||
# --- DELETE ---
|
||||
|
||||
Reference in New Issue
Block a user