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:
@@ -15,7 +15,10 @@ import threading
|
||||
from collections import deque
|
||||
from collections.abc import AsyncIterator, Callable
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from fluksio.flow.namespace import Rename
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -24,6 +27,8 @@ DISPATCH_BUDGET = 1024
|
||||
LOG_HISTORY = 400
|
||||
#: How many of a message's last artifact digests are remembered.
|
||||
RECENT_DIGESTS = 8
|
||||
#: How many turns of the loop `settle` gives the dispatch at most.
|
||||
SETTLE_TURNS = 100
|
||||
|
||||
|
||||
def _critical(event: dict[str, Any]) -> bool:
|
||||
@@ -211,6 +216,29 @@ class EventBus:
|
||||
if self._loop is not None:
|
||||
self._loop.call_soon(self._dispatch)
|
||||
|
||||
async def settle(self) -> None:
|
||||
"""Wait until what was published so far has reached every subscriber.
|
||||
|
||||
For a rename, before any key changes: an event a node published under
|
||||
the old key is then recorded under it. Bounded, since a busy bus may
|
||||
never be empty.
|
||||
"""
|
||||
for _ in range(SETTLE_TURNS):
|
||||
with self._pending_lock:
|
||||
if not self._flush_scheduled:
|
||||
return
|
||||
await asyncio.sleep(0)
|
||||
|
||||
def rename(self, rename: Rename) -> None:
|
||||
"""Keep emit counts and recent digests under the names a key rename
|
||||
gave their nodes and messages, so a client reconnecting or a device
|
||||
fetching a recent frame finds them there. Rebound, not changed in
|
||||
place: publishers on other threads write to them."""
|
||||
self.emits = {rename.name(node): n for node, n in list(self.emits.items())}
|
||||
self.digests = {
|
||||
rename.name(name): recent for name, recent in list(self.digests.items())
|
||||
}
|
||||
|
||||
def dropped(self, queue: asyncio.Queue[dict[str, Any]]) -> bool:
|
||||
"""Whether this subscriber lost events since it last asked.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user