Add Galaxy repository API and clients
This commit is contained in:
@@ -98,6 +98,76 @@ MXAccess commands and preserve raw replies on typed command exceptions.
|
||||
Canceling a Python task cancels the client-side gRPC call or stream wait. It
|
||||
does not abort an in-flight MXAccess COM call inside the worker process.
|
||||
|
||||
## Galaxy Repository Browse
|
||||
|
||||
The `GalaxyRepositoryClient` wraps the read-only `GalaxyRepository` gRPC
|
||||
service. It lets callers test connectivity to the AVEVA System Platform
|
||||
Galaxy Repository (ZB SQL database), read the last deploy timestamp, and
|
||||
enumerate the deployed object hierarchy plus each object's dynamic
|
||||
attributes:
|
||||
|
||||
```python
|
||||
from mxgateway import GalaxyRepositoryClient
|
||||
|
||||
async with await GalaxyRepositoryClient.connect(
|
||||
endpoint="localhost:5000",
|
||||
api_key="<gateway-api-key>",
|
||||
plaintext=True,
|
||||
) as galaxy:
|
||||
if not await galaxy.test_connection():
|
||||
raise RuntimeError("gateway cannot reach the Galaxy Repository DB")
|
||||
|
||||
last_deploy = await galaxy.get_last_deploy_time()
|
||||
print(f"last deploy: {last_deploy}")
|
||||
|
||||
for obj in await galaxy.discover_hierarchy():
|
||||
print(obj.tag_name, obj.contained_name)
|
||||
for attr in obj.attributes:
|
||||
print(" ", attr.attribute_name, "->", attr.full_tag_reference)
|
||||
```
|
||||
|
||||
The methods return native Python types (`bool`, `datetime | None`, and a
|
||||
`list[GalaxyObject]` of generated proto messages) so callers can index
|
||||
into the hierarchy without learning the underlying stub class. The
|
||||
service requires the `metadata:read` scope on the API key.
|
||||
|
||||
### Watching deploy events
|
||||
|
||||
`GalaxyRepositoryClient.watch_deploy_events` opens a server-streaming
|
||||
subscription that emits the current cached deploy state immediately and
|
||||
then one `DeployEvent` per new Galaxy deploy. `sequence` is monotonic per
|
||||
gateway start; gaps mean events were dropped from the per-subscriber
|
||||
buffer. Pass `last_seen_deploy_time` to suppress the bootstrap event when
|
||||
the caller already has the current state cached:
|
||||
|
||||
```python
|
||||
from datetime import datetime, timezone
|
||||
from mxgateway import DeployEvent, GalaxyRepositoryClient
|
||||
|
||||
async with await GalaxyRepositoryClient.connect(
|
||||
endpoint="localhost:5000",
|
||||
api_key="<gateway-api-key>",
|
||||
plaintext=True,
|
||||
) as galaxy:
|
||||
last_seen: datetime | None = None
|
||||
async for event in galaxy.watch_deploy_events(last_seen_deploy_time=last_seen):
|
||||
assert isinstance(event, DeployEvent)
|
||||
print(
|
||||
f"#{event.sequence} deploy={event.time_of_last_deploy.ToDatetime(tzinfo=timezone.utc)} "
|
||||
f"objects={event.object_count} attributes={event.attribute_count}"
|
||||
)
|
||||
if event.time_of_last_deploy_present:
|
||||
last_seen = event.time_of_last_deploy.ToDatetime(tzinfo=timezone.utc)
|
||||
```
|
||||
|
||||
The method returns an async iterator yielding the generated `DeployEvent`
|
||||
proto. Breaking out of the loop, calling `aclose()` on the iterator, or
|
||||
cancelling the surrounding task closes the underlying gRPC stream
|
||||
cleanly. The streaming RPC requires the same `metadata:read` scope as
|
||||
the other Galaxy methods. The CLI does not currently expose a
|
||||
streaming `watch-deploy-events` subcommand — use the library API
|
||||
directly when subscribing to deploy events from Python.
|
||||
|
||||
## Authentication And TLS
|
||||
|
||||
`ClientOptions.api_key` adds this metadata to unary calls and streams:
|
||||
|
||||
Reference in New Issue
Block a user