feat(gateway): slot v2 loader (contract C1)
This commit is contained in:
0
ingestor/io/__init__.py
Normal file
0
ingestor/io/__init__.py
Normal file
25
ingestor/io/slots.py
Normal file
25
ingestor/io/slots.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""Parse the slot v2 structure written by the Orchestrator to Redis (contract C1)."""
|
||||
|
||||
SERVER_FIELDS = ('server_id', 'url', 'server_uri', 'use_security', 'subscription_period_ms')
|
||||
|
||||
|
||||
def _parse_tag(address: str, tag: dict) -> dict:
|
||||
names = tag.get('names')
|
||||
if not names:
|
||||
raise ValueError(f'tag {address!r} has no names')
|
||||
return {
|
||||
'frequency': tag['frequency'],
|
||||
'names': names,
|
||||
'active_read': tag.get('active_read', {'enabled': False}),
|
||||
}
|
||||
|
||||
|
||||
def _parse_server(server: dict) -> dict:
|
||||
parsed = {field: server[field] for field in SERVER_FIELDS if field in server}
|
||||
parsed['tags'] = {addr: _parse_tag(addr, tag) for addr, tag in server['tags'].items()}
|
||||
return parsed
|
||||
|
||||
|
||||
def parse_slot(raw: dict) -> dict:
|
||||
"""Normalize a raw slot v2 dict into `{server_name: {..., tags: {addr: tag}}}`."""
|
||||
return {name: _parse_server(server) for name, server in raw.items()}
|
||||
Reference in New Issue
Block a user