trustgraph/trustgraph-base/trustgraph/base/triples_store_service.py
Cyber MacGeddon db05427d0e IAM tech spec: Auth and access management current state and proposed
changes.

Support for separate workspaces

Addition of workspace CLI support for test purposes
2026-04-21 10:50:52 +01:00

65 lines
1.6 KiB
Python

"""
Triples store base class
"""
from __future__ import annotations
from argparse import ArgumentParser
import logging
from .. schema import Triples
from .. base import FlowProcessor, ConsumerSpec
from .. exceptions import TooManyRequests
# Module logger
logger = logging.getLogger(__name__)
default_ident = "triples-write"
class TriplesStoreService(FlowProcessor):
"""
Component for maintaining the triples store.
This service acts as a processor in the flow that receives knowledge triples
and writes them persistently into an overarching graph database or equivalent backend.
"""
def __init__(self, **params):
id = params.get("id")
super(TriplesStoreService, self).__init__(**params | { "id": id })
self.register_specification(
ConsumerSpec(
name = "input",
schema = Triples,
handler = self.on_message
)
)
async def on_message(self, msg, consumer, flow):
try:
request = msg.value()
# Workspace is derived from the flow the message arrived on,
# not from fields in the message payload. Topic routing is
# the isolation boundary.
await self.store_triples(flow.workspace, request)
except TooManyRequests as e:
raise e
except Exception as e:
logger.error(f"Exception in triples store service: {e}", exc_info=True)
raise e
@staticmethod
def add_args(parser: ArgumentParser) -> None:
FlowProcessor.add_args(parser)