"""Deploy one app (or none) and record every change of deployed/deploying/state with a timestamp.""" import sys, time, json import walk as w app = sys.argv[1]; cap = int(sys.argv[2]) if len(sys.argv) > 2 else 900 w.login() if "--deploy" in sys.argv: vals = w.deploy_values(app, app) c, d = w.ctl("POST", f"/api/stacks/{app}/deploy", {"values": vals} if vals else {}) w.say(f"deploy {app} -> {c} {str(d)[:160]}") last = None; t0 = time.time() while time.time() - t0 < cap: st = w.stack(app) cur = (st.get("deployed"), st.get("deploying"), st.get("state"), st.get("deploy_error")) if cur != last: w.say(f"+{time.time()-t0:6.1f}s {app}: deployed={cur[0]} deploying={cur[1]} state={cur[2]} err={str(cur[3])[:200]!r}") last = cur if "--until-settled" in sys.argv and cur[1] is False and time.time() - t0 > 30 and cur[2] in ("running", "not_deployed", "error", "stopped", "exited"): # settled: keep watching 60 s more for late flips end = time.time() + 60 while time.time() < end: st = w.stack(app); c2 = (st.get("deployed"), st.get("deploying"), st.get("state"), st.get("deploy_error")) if c2 != last: w.say(f"+{time.time()-t0:6.1f}s {app}: deployed={c2[0]} deploying={c2[1]} state={c2[2]} err={str(c2[3])[:200]!r}"); last = c2 time.sleep(3) break time.sleep(3) w.say("final:", json.dumps({k: w.stack(app).get(k) for k in ("deployed","deploying","state","deploy_error","containers")}, default=str)[:600])