forked from cadence-workflow/cadence-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
43 lines (30 loc) · 1.04 KB
/
client.py
File metadata and controls
43 lines (30 loc) · 1.04 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
import os
import socket
from typing import TypedDict
from cadence.api.v1.service_worker_pb2_grpc import WorkerAPIStub
from grpc.aio import Channel
from cadence.data_converter import DataConverter
class ClientOptions(TypedDict, total=False):
domain: str
identity: str
data_converter: DataConverter
class Client:
def __init__(self, channel: Channel, options: ClientOptions) -> None:
self._channel = channel
self._worker_stub = WorkerAPIStub(channel)
self._options = options
self._identity = options["identity"] if "identity" in options else f"{os.getpid()}@{socket.gethostname()}"
@property
def data_converter(self) -> DataConverter:
return self._options["data_converter"]
@property
def domain(self) -> str:
return self._options["domain"]
@property
def identity(self) -> str:
return self._identity
@property
def worker_stub(self) -> WorkerAPIStub:
return self._worker_stub
async def close(self) -> None:
await self._channel.close()