dbos 1.14.0a2__py3-none-any.whl → 1.14.0a4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dbos/_core.py +25 -5
- dbos/_outcome.py +67 -13
- {dbos-1.14.0a2.dist-info → dbos-1.14.0a4.dist-info}/METADATA +1 -1
- {dbos-1.14.0a2.dist-info → dbos-1.14.0a4.dist-info}/RECORD +7 -7
- {dbos-1.14.0a2.dist-info → dbos-1.14.0a4.dist-info}/WHEEL +0 -0
- {dbos-1.14.0a2.dist-info → dbos-1.14.0a4.dist-info}/entry_points.txt +0 -0
- {dbos-1.14.0a2.dist-info → dbos-1.14.0a4.dist-info}/licenses/LICENSE +0 -0
dbos/_core.py
CHANGED
@@ -19,8 +19,6 @@ from typing import (
|
|
19
19
|
cast,
|
20
20
|
)
|
21
21
|
|
22
|
-
import psycopg
|
23
|
-
|
24
22
|
from dbos._outcome import Immediate, NoResult, Outcome, Pending
|
25
23
|
from dbos._utils import GlobalParams, retriable_postgres_exception
|
26
24
|
|
@@ -58,6 +56,7 @@ from ._error import (
|
|
58
56
|
DBOSWorkflowConflictIDError,
|
59
57
|
DBOSWorkflowFunctionNotFoundError,
|
60
58
|
)
|
59
|
+
from ._logger import dbos_logger
|
61
60
|
from ._registrations import (
|
62
61
|
DEFAULT_MAX_RECOVERY_ATTEMPTS,
|
63
62
|
get_config_name,
|
@@ -98,6 +97,14 @@ F = TypeVar("F", bound=Callable[..., Any])
|
|
98
97
|
TEMP_SEND_WF_NAME = "<temp>.temp_send_workflow"
|
99
98
|
|
100
99
|
|
100
|
+
def check_is_in_coroutine() -> bool:
|
101
|
+
try:
|
102
|
+
asyncio.get_running_loop()
|
103
|
+
return True
|
104
|
+
except RuntimeError:
|
105
|
+
return False
|
106
|
+
|
107
|
+
|
101
108
|
class WorkflowHandleFuture(Generic[R]):
|
102
109
|
|
103
110
|
def __init__(self, workflow_id: str, future: Future[R], dbos: "DBOS"):
|
@@ -830,11 +837,16 @@ def workflow_wrapper(
|
|
830
837
|
dbos._sys_db.record_get_result(workflow_id, serialized_r, None)
|
831
838
|
return r
|
832
839
|
|
840
|
+
if check_is_in_coroutine() and not inspect.iscoroutinefunction(func):
|
841
|
+
dbos_logger.warning(
|
842
|
+
f"Sync workflow ({get_dbos_func_name(func)}) shouldn't be invoked from within another async function. Define it as async or use asyncio.to_thread instead."
|
843
|
+
)
|
844
|
+
|
833
845
|
outcome = (
|
834
|
-
wfOutcome.wrap(init_wf)
|
846
|
+
wfOutcome.wrap(init_wf, dbos=dbos)
|
835
847
|
.also(DBOSAssumeRole(rr))
|
836
848
|
.also(enterWorkflowCtxMgr(attributes))
|
837
|
-
.then(record_get_result)
|
849
|
+
.then(record_get_result, dbos=dbos)
|
838
850
|
)
|
839
851
|
return outcome() # type: ignore
|
840
852
|
|
@@ -1011,6 +1023,10 @@ def decorate_transaction(
|
|
1011
1023
|
assert (
|
1012
1024
|
ctx.is_workflow()
|
1013
1025
|
), "Transactions must be called from within workflows"
|
1026
|
+
if check_is_in_coroutine():
|
1027
|
+
dbos_logger.warning(
|
1028
|
+
f"Transaction function ({get_dbos_func_name(func)}) shouldn't be invoked from within another async function. Use asyncio.to_thread instead."
|
1029
|
+
)
|
1014
1030
|
with DBOSAssumeRole(rr):
|
1015
1031
|
return invoke_tx(*args, **kwargs)
|
1016
1032
|
else:
|
@@ -1146,7 +1162,7 @@ def decorate_step(
|
|
1146
1162
|
|
1147
1163
|
outcome = (
|
1148
1164
|
stepOutcome.then(record_step_result)
|
1149
|
-
.intercept(check_existing_result)
|
1165
|
+
.intercept(check_existing_result, dbos=dbos)
|
1150
1166
|
.also(EnterDBOSStep(attributes))
|
1151
1167
|
)
|
1152
1168
|
return outcome()
|
@@ -1155,6 +1171,10 @@ def decorate_step(
|
|
1155
1171
|
|
1156
1172
|
@wraps(func)
|
1157
1173
|
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
1174
|
+
if check_is_in_coroutine() and not inspect.iscoroutinefunction(func):
|
1175
|
+
dbos_logger.warning(
|
1176
|
+
f"Sync step ({get_dbos_func_name(func)}) shouldn't be invoked from within another async function. Define it as async or use asyncio.to_thread instead."
|
1177
|
+
)
|
1158
1178
|
# If the step is called from a workflow, run it as a step.
|
1159
1179
|
# Otherwise, run it as a normal function.
|
1160
1180
|
ctx = get_local_dbos_context()
|
dbos/_outcome.py
CHANGED
@@ -2,9 +2,24 @@ import asyncio
|
|
2
2
|
import contextlib
|
3
3
|
import inspect
|
4
4
|
import time
|
5
|
-
from typing import
|
5
|
+
from typing import (
|
6
|
+
TYPE_CHECKING,
|
7
|
+
Any,
|
8
|
+
Callable,
|
9
|
+
Coroutine,
|
10
|
+
Optional,
|
11
|
+
Protocol,
|
12
|
+
TypeVar,
|
13
|
+
Union,
|
14
|
+
cast,
|
15
|
+
)
|
6
16
|
|
7
17
|
from dbos._context import EnterDBOSStepRetry
|
18
|
+
from dbos._error import DBOSException
|
19
|
+
from dbos._registrations import get_dbos_func_name
|
20
|
+
|
21
|
+
if TYPE_CHECKING:
|
22
|
+
from ._dbos import DBOS
|
8
23
|
|
9
24
|
T = TypeVar("T")
|
10
25
|
R = TypeVar("R")
|
@@ -24,10 +39,15 @@ class NoResult:
|
|
24
39
|
class Outcome(Protocol[T]):
|
25
40
|
|
26
41
|
def wrap(
|
27
|
-
self,
|
42
|
+
self,
|
43
|
+
before: Callable[[], Callable[[Callable[[], T]], R]],
|
44
|
+
*,
|
45
|
+
dbos: Optional["DBOS"] = None,
|
28
46
|
) -> "Outcome[R]": ...
|
29
47
|
|
30
|
-
def then(
|
48
|
+
def then(
|
49
|
+
self, next: Callable[[Callable[[], T]], R], *, dbos: Optional["DBOS"] = None
|
50
|
+
) -> "Outcome[R]": ...
|
31
51
|
|
32
52
|
def also(
|
33
53
|
self, cm: contextlib.AbstractContextManager[Any, bool]
|
@@ -41,7 +61,10 @@ class Outcome(Protocol[T]):
|
|
41
61
|
) -> "Outcome[T]": ...
|
42
62
|
|
43
63
|
def intercept(
|
44
|
-
self,
|
64
|
+
self,
|
65
|
+
interceptor: Callable[[], Union[NoResult, T]],
|
66
|
+
*,
|
67
|
+
dbos: Optional["DBOS"] = None,
|
45
68
|
) -> "Outcome[T]": ...
|
46
69
|
|
47
70
|
def __call__(self) -> Union[T, Coroutine[Any, Any, T]]: ...
|
@@ -63,11 +86,17 @@ class Immediate(Outcome[T]):
|
|
63
86
|
def __init__(self, func: Callable[[], T]):
|
64
87
|
self._func = func
|
65
88
|
|
66
|
-
def then(
|
89
|
+
def then(
|
90
|
+
self,
|
91
|
+
next: Callable[[Callable[[], T]], R],
|
92
|
+
dbos: Optional["DBOS"] = None,
|
93
|
+
) -> "Immediate[R]":
|
67
94
|
return Immediate(lambda: next(self._func))
|
68
95
|
|
69
96
|
def wrap(
|
70
|
-
self,
|
97
|
+
self,
|
98
|
+
before: Callable[[], Callable[[Callable[[], T]], R]],
|
99
|
+
dbos: Optional["DBOS"] = None,
|
71
100
|
) -> "Immediate[R]":
|
72
101
|
return Immediate(lambda: before()(self._func))
|
73
102
|
|
@@ -79,7 +108,10 @@ class Immediate(Outcome[T]):
|
|
79
108
|
return intercepted if not isinstance(intercepted, NoResult) else func()
|
80
109
|
|
81
110
|
def intercept(
|
82
|
-
self,
|
111
|
+
self,
|
112
|
+
interceptor: Callable[[], Union[NoResult, T]],
|
113
|
+
*,
|
114
|
+
dbos: Optional["DBOS"] = None,
|
83
115
|
) -> "Immediate[T]":
|
84
116
|
return Immediate[T](lambda: Immediate._intercept(self._func, interceptor))
|
85
117
|
|
@@ -142,7 +174,12 @@ class Pending(Outcome[T]):
|
|
142
174
|
async def _wrap(
|
143
175
|
func: Callable[[], Coroutine[Any, Any, T]],
|
144
176
|
before: Callable[[], Callable[[Callable[[], T]], R]],
|
177
|
+
*,
|
178
|
+
dbos: Optional["DBOS"] = None,
|
145
179
|
) -> R:
|
180
|
+
# Make sure the executor pool is configured correctly
|
181
|
+
if dbos is not None:
|
182
|
+
await dbos._configure_asyncio_thread_pool()
|
146
183
|
after = await asyncio.to_thread(before)
|
147
184
|
try:
|
148
185
|
value = await func()
|
@@ -151,12 +188,17 @@ class Pending(Outcome[T]):
|
|
151
188
|
return await asyncio.to_thread(after, lambda: Pending._raise(exp))
|
152
189
|
|
153
190
|
def wrap(
|
154
|
-
self,
|
191
|
+
self,
|
192
|
+
before: Callable[[], Callable[[Callable[[], T]], R]],
|
193
|
+
*,
|
194
|
+
dbos: Optional["DBOS"] = None,
|
155
195
|
) -> "Pending[R]":
|
156
|
-
return Pending[R](lambda: Pending._wrap(self._func, before))
|
196
|
+
return Pending[R](lambda: Pending._wrap(self._func, before, dbos=dbos))
|
157
197
|
|
158
|
-
def then(
|
159
|
-
|
198
|
+
def then(
|
199
|
+
self, next: Callable[[Callable[[], T]], R], *, dbos: Optional["DBOS"] = None
|
200
|
+
) -> "Pending[R]":
|
201
|
+
return Pending[R](lambda: Pending._wrap(self._func, lambda: next, dbos=dbos))
|
160
202
|
|
161
203
|
@staticmethod
|
162
204
|
async def _also( # type: ignore
|
@@ -173,12 +215,24 @@ class Pending(Outcome[T]):
|
|
173
215
|
async def _intercept(
|
174
216
|
func: Callable[[], Coroutine[Any, Any, T]],
|
175
217
|
interceptor: Callable[[], Union[NoResult, T]],
|
218
|
+
*,
|
219
|
+
dbos: Optional["DBOS"] = None,
|
176
220
|
) -> T:
|
221
|
+
# Make sure the executor pool is configured correctly
|
222
|
+
if dbos is not None:
|
223
|
+
await dbos._configure_asyncio_thread_pool()
|
177
224
|
intercepted = await asyncio.to_thread(interceptor)
|
178
225
|
return intercepted if not isinstance(intercepted, NoResult) else await func()
|
179
226
|
|
180
|
-
def intercept(
|
181
|
-
|
227
|
+
def intercept(
|
228
|
+
self,
|
229
|
+
interceptor: Callable[[], Union[NoResult, T]],
|
230
|
+
*,
|
231
|
+
dbos: Optional["DBOS"] = None,
|
232
|
+
) -> "Pending[T]":
|
233
|
+
return Pending[T](
|
234
|
+
lambda: Pending._intercept(self._func, interceptor, dbos=dbos)
|
235
|
+
)
|
182
236
|
|
183
237
|
@staticmethod
|
184
238
|
async def _retry(
|
@@ -1,7 +1,7 @@
|
|
1
|
-
dbos-1.14.
|
2
|
-
dbos-1.14.
|
3
|
-
dbos-1.14.
|
4
|
-
dbos-1.14.
|
1
|
+
dbos-1.14.0a4.dist-info/METADATA,sha256=H6-_1NWU-g_Z0T3icZiFc1ZaDVv5_zqFdaf2AUC0vWU,13268
|
2
|
+
dbos-1.14.0a4.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
|
3
|
+
dbos-1.14.0a4.dist-info/entry_points.txt,sha256=_QOQ3tVfEjtjBlr1jS4sHqHya9lI2aIEIWkz8dqYp14,58
|
4
|
+
dbos-1.14.0a4.dist-info/licenses/LICENSE,sha256=VGZit_a5-kdw9WT6fY5jxAWVwGQzgLFyPWrcVVUhVNU,1067
|
5
5
|
dbos/__init__.py,sha256=NssPCubaBxdiKarOWa-wViz1hdJSkmBGcpLX_gQ4NeA,891
|
6
6
|
dbos/__main__.py,sha256=G7Exn-MhGrVJVDbgNlpzhfh8WMX_72t3_oJaFT9Lmt8,653
|
7
7
|
dbos/_admin_server.py,sha256=e8ELhcDWqR3_PNobnNgUvLGh5lzZq0yFSF6dvtzoQRI,16267
|
@@ -28,7 +28,7 @@ dbos/_client.py,sha256=_3Wc2QQc5VDcBuJ3cNb-lWg439OuITo2ex4Y7qb9l44,18800
|
|
28
28
|
dbos/_conductor/conductor.py,sha256=3E_hL3c9g9yWqKZkvI6KA0-ZzPMPRo06TOzT1esMiek,24114
|
29
29
|
dbos/_conductor/protocol.py,sha256=q3rgLxINFtWFigdOONc-4gX4vn66UmMlJQD6Kj8LnL4,7420
|
30
30
|
dbos/_context.py,sha256=IMboNgbCqTxfIORqeifE3da-Ce5siMz7MYMLPk5M-AQ,26851
|
31
|
-
dbos/_core.py,sha256=
|
31
|
+
dbos/_core.py,sha256=Lm4gCAVZqNbJdZlXPQ7WROrdhhJ6tWhNzbpe5hgEDSs,49866
|
32
32
|
dbos/_croniter.py,sha256=XHAyUyibs_59sJQfSNWkP7rqQY6_XrlfuuCxk4jYqek,47559
|
33
33
|
dbos/_dbos.py,sha256=wKLN7W1ej6cyEOHnCtt3-awnU6SR6MQAlOvTTt5_N-E,58219
|
34
34
|
dbos/_dbos_config.py,sha256=_26ktif8qAZW4Ujg6dZfLkYO7dE4CI8b3IQbw_5YkpA,25710
|
@@ -42,7 +42,7 @@ dbos/_kafka.py,sha256=Gm4fHWl7gYb-i5BMvwNwm5Km3z8zQpseqdMgqgFjlGI,4252
|
|
42
42
|
dbos/_kafka_message.py,sha256=NYvOXNG3Qn7bghn1pv3fg4Pbs86ILZGcK4IB-MLUNu0,409
|
43
43
|
dbos/_logger.py,sha256=vvBL4kzJWBPtfcHIuL0nJAq5cgpeo_D3IiIUDicWLOg,4732
|
44
44
|
dbos/_migration.py,sha256=wJrSTYerlkYDFYmkTqo4a7n4WaKmqXh8BdkUEzgSEQQ,10898
|
45
|
-
dbos/_outcome.py,sha256=
|
45
|
+
dbos/_outcome.py,sha256=7HvosMfEHTh1U5P6xok7kFTGLwa2lPaul0YApb3UnN4,8191
|
46
46
|
dbos/_queue.py,sha256=0kJTPwXy3nZ4Epzt-lHky9M9S4L31645drPGFR8fIJY,4854
|
47
47
|
dbos/_recovery.py,sha256=K-wlFhdf4yGRm6cUzyhcTjQUS0xp2T5rdNMLiiBErYg,2882
|
48
48
|
dbos/_registrations.py,sha256=bEOntObnWaBylnebr5ZpcX2hk7OVLDd1z4BvW4_y3zA,7380
|
@@ -75,4 +75,4 @@ dbos/cli/migration.py,sha256=5GiyagLZkyVvDz3StYxtFdkFoKFCmh6eSXjzsIGhZ_A,3330
|
|
75
75
|
dbos/dbos-config.schema.json,sha256=LyUT1DOTaAwOP6suxQGS5KemVIqXGPyu_q7Hbo0neA8,6192
|
76
76
|
dbos/py.typed,sha256=QfzXT1Ktfk3Rj84akygc7_42z0lRpCq0Ilh8OXI6Zas,44
|
77
77
|
version/__init__.py,sha256=L4sNxecRuqdtSFdpUGX3TtBi9KL3k7YsZVIvv-fv9-A,1678
|
78
|
-
dbos-1.14.
|
78
|
+
dbos-1.14.0a4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|