-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathclient_types.py
More file actions
153 lines (133 loc) · 4.1 KB
/
client_types.py
File metadata and controls
153 lines (133 loc) · 4.1 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#
# Copyright (c) 2023-2025 - Restate Software, Inc., Restate GmbH
#
# This file is part of the Restate SDK for Python,
# which is released under the MIT license.
#
# You can find a copy of the license in file LICENSE in the root
# directory of this repository or package, or at
# https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
#
"""
Type definitions for the Restate client.
"""
import abc
from datetime import timedelta
import typing
from .context import HandlerType
I = typing.TypeVar("I")
O = typing.TypeVar("O")
class RestateClientSendHandle:
"""
A handle for a send operation.
This is used to track the status of a send operation.
"""
def __init__(self, invocation_id: str, status_code: int):
self.invocation_id = invocation_id
self.status_code = status_code
class HttpError(Exception):
"""
An error that occurs during an HTTP request.
"""
def __init__(self, status_code: int, message: str, body: str | None = None):
super().__init__(f"HTTP {status_code}: {message}")
self.status_code = status_code
self.message = message
self.body = body
class RestateClient(abc.ABC):
"""
An abstract base class for a Restate client.
This class defines the interface for a Restate client.
"""
@abc.abstractmethod
async def service_call(
self,
tpe: HandlerType[I, O],
arg: I,
idempotency_key: str | None = None,
headers: typing.Dict[str, str] | None = None,
) -> O:
"""Make an RPC call to the given handler"""
pass
@abc.abstractmethod
async def service_send(
self,
tpe: HandlerType[I, O],
arg: I,
send_delay: typing.Optional[timedelta] = None,
idempotency_key: str | None = None,
headers: typing.Dict[str, str] | None = None,
) -> RestateClientSendHandle:
"""Make a send operation to the given handler"""
pass
@abc.abstractmethod
async def object_call(
self,
tpe: HandlerType[I, O],
key: str,
arg: I,
idempotency_key: str | None = None,
headers: typing.Dict[str, str] | None = None,
) -> O:
"""Make an RPC call to the given object handler"""
pass
@abc.abstractmethod
async def object_send(
self,
tpe: HandlerType[I, O],
key: str,
arg: I,
send_delay: typing.Optional[timedelta] = None,
idempotency_key: str | None = None,
headers: typing.Dict[str, str] | None = None,
) -> RestateClientSendHandle:
"""Make a send operation to the given object handler"""
pass
@abc.abstractmethod
async def workflow_call(
self,
tpe: HandlerType[I, O],
key: str,
arg: I,
idempotency_key: str | None = None,
headers: typing.Dict[str, str] | None = None,
) -> O:
"""Make an RPC call to the given workflow handler"""
pass
@abc.abstractmethod
async def workflow_send(
self,
tpe: HandlerType[I, O],
key: str,
arg: I,
send_delay: typing.Optional[timedelta] = None,
idempotency_key: str | None = None,
headers: typing.Dict[str, str] | None = None,
) -> RestateClientSendHandle:
"""Make a send operation to the given workflow handler"""
pass
@abc.abstractmethod
async def generic_call(
self,
service: str,
handler: str,
arg: bytes,
key: str | None = None,
idempotency_key: str | None = None,
headers: typing.Dict[str, str] | None = None,
) -> bytes:
"""Make a generic RPC call to the given service and handler"""
pass
@abc.abstractmethod
async def generic_send(
self,
service: str,
handler: str,
arg: bytes,
key: str | None = None,
send_delay: timedelta | None = None,
idempotency_key: str | None = None,
headers: typing.Dict[str, str] | None = None,
) -> RestateClientSendHandle:
"""Make a generic send operation to the given service and handler"""
pass