mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 17:39:39 +02:00
Replace singleton LibrarianClient with per-flow instances via the new LibrarianSpec, giving each flow its own librarian tied to the workspace-scoped request/response queues from the blueprint. Move all workspace-scoped services (config, flow, librarian, knowledge) from a single base-queue response producer to per-workspace response producers created alongside the existing per-workspace request consumers. Update the gateway dispatcher and bootstrapper flow client to subscribe to the matching workspace-scoped response queues. Fix WorkspaceInit to register workspaces through the IAM create-workspace API so they appear in __workspaces__ and are visible to the gateway. Simplify the bootstrapper gate to only check config-svc reachability. Updated tests accordingly.
69 lines
2.4 KiB
Python
69 lines
2.4 KiB
Python
"""
|
|
Bootstrap framework: Initialiser base class and per-wake context.
|
|
|
|
See docs/tech-specs/bootstrap.md for the full design.
|
|
"""
|
|
|
|
import logging
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
|
|
@dataclass
|
|
class InitContext:
|
|
"""Shared per-wake context passed to each initialiser.
|
|
|
|
The bootstrapper constructs one of these on every wake cycle,
|
|
tears it down at cycle end, and passes it into each initialiser's
|
|
``run()`` method. Fields are short-lived and safe to use during
|
|
a single cycle only.
|
|
"""
|
|
|
|
logger: logging.Logger
|
|
config: Any # ConfigClient
|
|
make_flow_client: Any # callable(workspace) -> RequestResponse
|
|
make_iam_client: Any # callable() -> RequestResponse
|
|
|
|
|
|
class Initialiser:
|
|
"""Base class for bootstrap initialisers.
|
|
|
|
Subclasses implement :meth:`run`. The bootstrapper manages
|
|
completion state, flag comparison, retry and error handling —
|
|
subclasses describe only the work to perform.
|
|
|
|
Class attributes:
|
|
|
|
* ``wait_for_services`` (bool, default ``True``): when ``True`` the
|
|
initialiser only runs after the bootstrapper's service gate has
|
|
passed (config-svc reachable). Set ``False`` for
|
|
initialisers that bring up infrastructure the gate itself
|
|
depends on — principally Pulsar topology, without which
|
|
config-svc cannot come online.
|
|
"""
|
|
|
|
wait_for_services: bool = True
|
|
|
|
def __init__(self, **params):
|
|
# Subclasses should consume their own params via keyword
|
|
# arguments in their own __init__ signatures. This catch-all
|
|
# is here so any kwargs that filter through unnoticed don't
|
|
# raise TypeError on construction.
|
|
pass
|
|
|
|
async def run(self, ctx, old_flag, new_flag):
|
|
"""Perform initialisation work.
|
|
|
|
:param ctx: :class:`InitContext` with logger, config client,
|
|
flow-svc client.
|
|
:param old_flag: Previously-stored flag string, or ``None`` if
|
|
this initialiser has never successfully completed in this
|
|
deployment.
|
|
:param new_flag: Currently-configured flag. A string chosen
|
|
by the operator; typically something like ``"v1"``.
|
|
|
|
:raises: Any exception on failure. The bootstrapper catches,
|
|
logs, and re-runs on the next cycle; completion state is
|
|
only written on clean return.
|
|
"""
|
|
raise NotImplementedError
|