-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrpc_getter.py
35 lines (24 loc) · 943 Bytes
/
grpc_getter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
from functools import cache
import datastore_pb2_grpc as dstore_grpc
import grpc
# Functions in this file should be async,
# These functions should be the only components that are
# dependent on external services.
# Reuse channel and stub as much as possible, see https://grpc.io/docs/guides/performance/
@cache
def get_grpc_stub():
channel = grpc.aio.insecure_channel(f"{os.getenv('DSHOST', 'localhost')}:{os.getenv('DSPORT', '50050')}")
return dstore_grpc.DatastoreStub(channel)
async def get_obs_request(request):
grpc_stub = get_grpc_stub()
response = await grpc_stub.GetObservations(request)
return response
async def get_ts_ag_request(request):
grpc_stub = get_grpc_stub()
response = await grpc_stub.GetTSAttrGroups(request)
return response
async def get_extents_request(request):
grpc_stub = get_grpc_stub()
response = await grpc_stub.GetExtents(request)
return response