-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgrpc_getter.py
More file actions
43 lines (32 loc) · 1.11 KB
/
grpc_getter.py
File metadata and controls
43 lines (32 loc) · 1.11 KB
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
36
37
38
39
40
41
42
43
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')}",
options=[
(
"grpc.max_receive_message_length",
int(os.getenv("GRPC_MAX_MESSAGE_SIZE", 4194304)),
)
],
)
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