Rename orchestration, splice and routes: a Renamer runs one rename at a time, closing the gate, taking the controller lock and holding the engine, each waiting without a limit and saying what it waits for (summary rename status, rename_waiting); DELETE on the pending request or a closed connection calls it off until the journal begins (409 aborted); then journal, steps and audit, retried in the background on failure (503 completing); splice_renamed rebuilds the affected flows under the held lock keeping stopped, paused and parked work, history limits and device wiring refreshed before activation; AlertManager.rename and EventBus.rename/settle follow the names; flow and dashboard rename routes answer by code and repeat stored results; renamed, dashboard_changed and pipeline_rebuilt after release; fluksio serve reads flow files without building a FlowStore
This commit is contained in:
@@ -39,7 +39,7 @@ from fluksio.flow.demand import demand
|
||||
from fluksio.flow.events import EventBus
|
||||
from fluksio.flow.executor import ExecutionService
|
||||
from fluksio.flow.messages import MessageSpec, flow_of, qualify
|
||||
from fluksio.flow.namespace import touches
|
||||
from fluksio.flow.namespace import Rename, touches
|
||||
from fluksio.flow.nodes import (
|
||||
RESERVED_SETTINGS,
|
||||
AssistantNode,
|
||||
@@ -913,6 +913,75 @@ class FlowController:
|
||||
)
|
||||
self._rewired()
|
||||
|
||||
async def splice_renamed(self, rename: Rename, rebuilt: list[str]) -> None:
|
||||
"""Put the flows a key rename rewrote back into the graph, built from
|
||||
their new documents and named as they are now.
|
||||
|
||||
Under the controller lock, which the rename holds, with the engine
|
||||
held and the flows *rebuilt* (ids) torn down before their documents
|
||||
changed. Not `reload_flow`, which would take the lock again, nor
|
||||
`reload`, which clears every pause. Stopped flows stay stopped, which
|
||||
is stored by id, pauses carry over under the new keys and parked work
|
||||
stays parked. A rebuilt flow's quarantine is gone with its teardown,
|
||||
as on a publish. What the documents feed is refreshed before anything
|
||||
starts: history limits, device wiring and what devices are asked to
|
||||
send.
|
||||
"""
|
||||
pipeline = self.pipeline
|
||||
if pipeline is None:
|
||||
return
|
||||
paused = pipeline.paused_flows()
|
||||
builds = await run_in_threadpool(
|
||||
lambda: [(flow_id, self._build_one(flow_id)) for flow_id in rebuilt]
|
||||
)
|
||||
# By the name each node has now, so a failure carries over.
|
||||
previous = {rename.name(node_id): e for node_id, e in self.loaded.items()}
|
||||
loaded = dict(self.loaded)
|
||||
keys = []
|
||||
for flow_id, built in builds:
|
||||
if built is None:
|
||||
continue
|
||||
flow, nodes, entries, initial_values, enabled = built
|
||||
old, key = self._flow_keys.get(flow_id, flow.name), flow.name
|
||||
if old != key:
|
||||
pipeline.replace_flow(old, [])
|
||||
pipeline.replace_flow(key, nodes, initial_values)
|
||||
self._flow_keys[flow_id] = key
|
||||
for node_id, entry in entries.items():
|
||||
before = previous.get(node_id)
|
||||
if before is not None and before.last_error:
|
||||
entry.inherit_failure(before)
|
||||
loaded = {
|
||||
node_id: entry for node_id, entry in loaded.items() if entry.flow != old
|
||||
} | entries
|
||||
self._flow_inputs.pop(old, None)
|
||||
self._flow_inputs[key] = _declared_inputs(flow)[0]
|
||||
self.disabled = (self.disabled - {old}) | (set() if enabled else {key})
|
||||
self.batch = (self.batch - {old}) | (
|
||||
{key} if flow.mode == "batch" else set()
|
||||
)
|
||||
keys.append(key)
|
||||
self.loaded = loaded
|
||||
pipeline.set_disabled(self.disabled)
|
||||
# The replace cleared the pause of every flow it touched.
|
||||
for was in map(rename.flow, paused):
|
||||
if not pipeline.is_paused(was):
|
||||
pipeline.pause(was)
|
||||
self.issues = _collect_issues(
|
||||
self.loaded, pipeline, self._all_flow_inputs(), self.devices
|
||||
)
|
||||
if self.dashboards is not None:
|
||||
self.set_history_limits(
|
||||
await run_in_threadpool(self.dashboards.history_requirements)
|
||||
)
|
||||
if self.devices is not None:
|
||||
# Taken note of without telling the devices: the rename does,
|
||||
# once it has let go of the engine.
|
||||
await run_in_threadpool(demand.refresh)
|
||||
self._device_wiring = await run_in_threadpool(self.devices.wiring)
|
||||
for key in keys:
|
||||
await self._activate(key)
|
||||
|
||||
async def recheck(self, wait: float | None = FLOW_REBUILD_WAIT) -> None:
|
||||
"""Validate the built graph again without rebuilding anything.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user