Flows and dashboards are created by POST under an issued or superuser-pinned id; PUT only updates; deleted flows leave a tombstone with their key; the controller stores by id and runs by key, hooks live under /hooks/<flow id>; a key with state or queued work behind it is refused until cleared

This commit is contained in:
2026-11-02 17:41:23 +01:00
parent fae85f5ecb
commit 08a6376836
63 changed files with 2832 additions and 936 deletions
+33 -9
View File
@@ -238,7 +238,7 @@ class Client:
# -- flows -------------------------------------------------------------
def get_flow(self, name: str) -> dict[str, Any] | None:
"""The stored flow, draft included, or ``None`` if there is none."""
"""The stored flow with the id *name*, draft included, or ``None``."""
try:
result: dict[str, Any] = self._call("GET", f"/flows/{seg(name)}")
except ApiError as exc:
@@ -247,9 +247,23 @@ class Client:
raise
return result
def find_flow(self, key: str) -> dict[str, Any] | None:
"""The listing of the flow holding the key *key*, or ``None``."""
result = self._call("GET", "/flows/", params={"name": key})
found = list(result.get("data") or [])
return found[0] if found else None
def create_flow(self, document: dict[str, Any]) -> dict[str, Any]:
"""A new flow, under the id the engine issues for it."""
result: dict[str, Any] = self._call("POST", "/flows/", json=document)
return result
def put_flow(self, document: dict[str, Any]) -> dict[str, Any]:
"""Save over the flow *document* names by its id, or by its key for
one whose id is its key."""
flow_id = document.get("id") or document["name"]
result: dict[str, Any] = self._call(
"PUT", f"/flows/{seg(document['name'])}", json=document
"PUT", f"/flows/{seg(flow_id)}", json=document
)
return result
@@ -821,7 +835,11 @@ def _sync_one(
force: bool,
) -> SyncReport:
report = SyncReport(target.name)
stored = client.get_flow(target.name)
# The declared key is what an instance shares; the id is this engine's,
# and every request after the lookup names the flow by it.
found = client.find_flow(target.name)
flow_id = str(found["id"]) if found else ""
stored = client.get_flow(flow_id) if flow_id else None
version = 1
# What the drift check already read, so the write loop below does not ask
# the engine for every node's body a second time.
@@ -836,7 +854,11 @@ def _sync_one(
document = target.document(origin)
moved = _moved_code(stored, document)
saved = client.put_flow(document | {"version": version})
if stored is None:
saved = client.create_flow(document)
flow_id = str((saved.get("definition") or {}).get("id") or target.name)
else:
saved = client.put_flow(document | {"id": flow_id, "version": version})
# An engine older than the per-node digest parses the document without
# those fields and stores it without them, silently: no error, no 404, and
# a cache still keyed on the whole repository.
@@ -860,16 +882,16 @@ def _sync_one(
if not report.created:
stored_code = known.get(node_id)
if stored_code is None:
stored_code = client.get_source(target.name, node_id)
stored_code = client.get_source(flow_id, node_id)
if stored_code == code:
continue
client.put_source(target.name, node_id, code)
client.put_source(flow_id, node_id, code)
if node_id not in report.changed:
report.changed.append(node_id)
has_draft = bool((client.get_flow(target.name) or {}).get("has_draft"))
has_draft = bool((client.get_flow(flow_id) or {}).get("has_draft"))
if publish and has_draft:
client.publish(target.name, version)
client.publish(flow_id, version)
report.published = True
else:
# Only when one is actually there. "Nothing needed publishing" and
@@ -934,7 +956,9 @@ def _refuse_on_drift(
for stored_node in definition.get("nodes") or []:
node_id = str(stored_node.get("id"))
try:
entry = client.get_source_entry(target.name, node_id)
entry = client.get_source_entry(
str(definition.get("id") or target.name), node_id
)
except ApiError:
continue
if entry.get("missing"):