dbos 0.19.0a9__py3-none-any.whl → 0.20.0a2__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.

Potentially problematic release.


This version of dbos might be problematic. Click here for more details.

dbos/_admin_server.py CHANGED
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import json
4
+ import re
4
5
  import threading
5
6
  from functools import partial
6
7
  from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
@@ -15,6 +16,9 @@ if TYPE_CHECKING:
15
16
  _health_check_path = "/dbos-healthz"
16
17
  _workflow_recovery_path = "/dbos-workflow-recovery"
17
18
  _deactivate_path = "/deactivate"
19
+ # /workflows/:workflow_id/cancel
20
+ # /workflows/:workflow_id/resume
21
+ # /workflows/:workflow_id/restart
18
22
 
19
23
 
20
24
  class AdminServer:
@@ -79,12 +83,51 @@ class AdminRequestHandler(BaseHTTPRequestHandler):
79
83
  self._end_headers()
80
84
  self.wfile.write(json.dumps(workflow_ids).encode("utf-8"))
81
85
  else:
82
- self.send_response(404)
83
- self._end_headers()
86
+
87
+ restart_match = re.match(
88
+ r"^/workflows/(?P<workflow_id>[^/]+)/restart$", self.path
89
+ )
90
+ resume_match = re.match(
91
+ r"^/workflows/(?P<workflow_id>[^/]+)/resume$", self.path
92
+ )
93
+ cancel_match = re.match(
94
+ r"^/workflows/(?P<workflow_id>[^/]+)/cancel$", self.path
95
+ )
96
+
97
+ if restart_match:
98
+ workflow_id = restart_match.group("workflow_id")
99
+ self._handle_restart(workflow_id)
100
+ elif resume_match:
101
+ workflow_id = resume_match.group("workflow_id")
102
+ self._handle_resume(workflow_id)
103
+ elif cancel_match:
104
+ workflow_id = cancel_match.group("workflow_id")
105
+ self._handle_cancel(workflow_id)
106
+ else:
107
+ self.send_response(404)
108
+ self._end_headers()
84
109
 
85
110
  def log_message(self, format: str, *args: Any) -> None:
86
111
  return # Disable admin server request logging
87
112
 
113
+ def _handle_restart(self, workflow_id: str) -> None:
114
+ self.dbos.restart_workflow(workflow_id)
115
+ print("Restarting workflow", workflow_id)
116
+ self.send_response(204)
117
+ self._end_headers()
118
+
119
+ def _handle_resume(self, workflow_id: str) -> None:
120
+ print("Resuming workflow", workflow_id)
121
+ self.dbos.resume_workflow(workflow_id)
122
+ self.send_response(204)
123
+ self._end_headers()
124
+
125
+ def _handle_cancel(self, workflow_id: str) -> None:
126
+ print("Cancelling workflow", workflow_id)
127
+ self.dbos.cancel_workflow(workflow_id)
128
+ self.send_response(204)
129
+ self._end_headers()
130
+
88
131
 
89
132
  # Be consistent with DBOS-TS response.
90
133
  class PerfUtilization(TypedDict):
dbos/_core.py CHANGED
@@ -266,7 +266,9 @@ def _execute_workflow_wthread(
266
266
  raise
267
267
 
268
268
 
269
- def execute_workflow_by_id(dbos: "DBOS", workflow_id: str) -> "WorkflowHandle[Any]":
269
+ def execute_workflow_by_id(
270
+ dbos: "DBOS", workflow_id: str, startNew: bool = False
271
+ ) -> "WorkflowHandle[Any]":
270
272
  status = dbos._sys_db.get_workflow_status(workflow_id)
271
273
  if not status:
272
274
  raise DBOSRecoveryError(workflow_id, "Workflow status not found")
@@ -293,7 +295,8 @@ def execute_workflow_by_id(dbos: "DBOS", workflow_id: str) -> "WorkflowHandle[An
293
295
  workflow_id,
294
296
  f"Cannot execute workflow because instance '{iname}' is not registered",
295
297
  )
296
- with SetWorkflowID(workflow_id):
298
+
299
+ if startNew:
297
300
  return start_workflow(
298
301
  dbos,
299
302
  wf_func,
@@ -303,6 +306,17 @@ def execute_workflow_by_id(dbos: "DBOS", workflow_id: str) -> "WorkflowHandle[An
303
306
  *inputs["args"],
304
307
  **inputs["kwargs"],
305
308
  )
309
+ else:
310
+ with SetWorkflowID(workflow_id):
311
+ return start_workflow(
312
+ dbos,
313
+ wf_func,
314
+ status["queue_name"],
315
+ True,
316
+ dbos._registry.instance_info_map[iname],
317
+ *inputs["args"],
318
+ **inputs["kwargs"],
319
+ )
306
320
  elif status["class_name"] is not None:
307
321
  class_name = status["class_name"]
308
322
  if class_name not in dbos._registry.class_info_map:
@@ -310,7 +324,8 @@ def execute_workflow_by_id(dbos: "DBOS", workflow_id: str) -> "WorkflowHandle[An
310
324
  workflow_id,
311
325
  f"Cannot execute workflow because class '{class_name}' is not registered",
312
326
  )
313
- with SetWorkflowID(workflow_id):
327
+
328
+ if startNew:
314
329
  return start_workflow(
315
330
  dbos,
316
331
  wf_func,
@@ -320,8 +335,19 @@ def execute_workflow_by_id(dbos: "DBOS", workflow_id: str) -> "WorkflowHandle[An
320
335
  *inputs["args"],
321
336
  **inputs["kwargs"],
322
337
  )
338
+ else:
339
+ with SetWorkflowID(workflow_id):
340
+ return start_workflow(
341
+ dbos,
342
+ wf_func,
343
+ status["queue_name"],
344
+ True,
345
+ dbos._registry.class_info_map[class_name],
346
+ *inputs["args"],
347
+ **inputs["kwargs"],
348
+ )
323
349
  else:
324
- with SetWorkflowID(workflow_id):
350
+ if startNew:
325
351
  return start_workflow(
326
352
  dbos,
327
353
  wf_func,
@@ -330,6 +356,16 @@ def execute_workflow_by_id(dbos: "DBOS", workflow_id: str) -> "WorkflowHandle[An
330
356
  *inputs["args"],
331
357
  **inputs["kwargs"],
332
358
  )
359
+ else:
360
+ with SetWorkflowID(workflow_id):
361
+ return start_workflow(
362
+ dbos,
363
+ wf_func,
364
+ status["queue_name"],
365
+ True,
366
+ *inputs["args"],
367
+ **inputs["kwargs"],
368
+ )
333
369
 
334
370
 
335
371
  @overload
dbos/_dbos.py CHANGED
@@ -56,6 +56,7 @@ from ._registrations import (
56
56
  )
57
57
  from ._roles import default_required_roles, required_roles
58
58
  from ._scheduler import ScheduledWorkflow, scheduled
59
+ from ._sys_db import WorkflowStatusString
59
60
  from ._tracer import dbos_tracer
60
61
 
61
62
  if TYPE_CHECKING:
@@ -231,6 +232,7 @@ class DBOS:
231
232
  f"DBOS configured multiple times with conflicting information"
232
233
  )
233
234
  config = _dbos_global_registry.config
235
+
234
236
  _dbos_global_instance = super().__new__(cls)
235
237
  _dbos_global_instance.__init__(fastapi=fastapi, config=config, flask=flask) # type: ignore
236
238
  else:
@@ -767,6 +769,11 @@ class DBOS:
767
769
  """Execute a workflow by ID (for recovery)."""
768
770
  return execute_workflow_by_id(_get_dbos_instance(), workflow_id)
769
771
 
772
+ @classmethod
773
+ def restart_workflow(cls, workflow_id: str) -> None:
774
+ """Execute a workflow by ID (for recovery)."""
775
+ execute_workflow_by_id(_get_dbos_instance(), workflow_id, True)
776
+
770
777
  @classmethod
771
778
  def recover_pending_workflows(
772
779
  cls, executor_ids: List[str] = ["local"]
@@ -774,6 +781,18 @@ class DBOS:
774
781
  """Find all PENDING workflows and execute them."""
775
782
  return recover_pending_workflows(_get_dbos_instance(), executor_ids)
776
783
 
784
+ @classmethod
785
+ def cancel_workflow(cls, workflow_id: str) -> None:
786
+ """Cancel a workflow by ID."""
787
+ _get_dbos_instance()._sys_db.set_workflow_status(
788
+ workflow_id, WorkflowStatusString.CANCELLED, False
789
+ )
790
+
791
+ @classmethod
792
+ def resume_workflow(cls, workflow_id: str) -> None:
793
+ """Resume a workflow by ID."""
794
+ execute_workflow_by_id(_get_dbos_instance(), workflow_id, False)
795
+
777
796
  @classproperty
778
797
  def logger(cls) -> Logger:
779
798
  """Return the DBOS `Logger` for the current context."""
dbos/_fastapi.py CHANGED
@@ -94,7 +94,11 @@ def setup_fastapi_middleware(app: FastAPI, dbos: DBOS) -> None:
94
94
  with EnterDBOSHandler(attributes):
95
95
  ctx = assert_current_dbos_context()
96
96
  ctx.request = _make_request(request)
97
- workflow_id = request.headers.get("dbos-idempotency-key", "")
98
- with SetWorkflowID(workflow_id):
97
+ workflow_id = request.headers.get("dbos-idempotency-key")
98
+ if workflow_id is not None:
99
+ # Set the workflow ID for the handler
100
+ with SetWorkflowID(workflow_id):
101
+ response = await call_next(request)
102
+ else:
99
103
  response = await call_next(request)
100
104
  return response
dbos/_flask.py CHANGED
@@ -34,8 +34,12 @@ class FlaskMiddleware:
34
34
  with EnterDBOSHandler(attributes):
35
35
  ctx = assert_current_dbos_context()
36
36
  ctx.request = _make_request(request)
37
- workflow_id = request.headers.get("dbos-idempotency-key", "")
38
- with SetWorkflowID(workflow_id):
37
+ workflow_id = request.headers.get("dbos-idempotency-key")
38
+ if workflow_id is not None:
39
+ # Set the workflow ID for the handler
40
+ with SetWorkflowID(workflow_id):
41
+ response = self.app(environ, start_response)
42
+ else:
39
43
  response = self.app(environ, start_response)
40
44
  return response
41
45
 
@@ -1,3 +1,6 @@
1
+ import importlib
2
+ import os
3
+ import sys
1
4
  from typing import Any, List, Optional, cast
2
5
 
3
6
  import typer
@@ -6,6 +9,7 @@ from rich import print
6
9
  from dbos import DBOS
7
10
 
8
11
  from . import _serialization, load_config
12
+ from ._core import execute_workflow_by_id
9
13
  from ._dbos_config import ConfigFile, _is_valid_app_name
10
14
  from ._sys_db import (
11
15
  GetWorkflowsInput,
@@ -123,11 +127,6 @@ def _cancel_workflow(config: ConfigFile, uuid: str) -> None:
123
127
  sys_db.destroy()
124
128
 
125
129
 
126
- def _reattempt_workflow(uuid: str, startNewWorkflow: bool) -> None:
127
- print(f"Reattempt workflow info for {uuid} not implemented")
128
- return
129
-
130
-
131
130
  def _get_workflow_info(
132
131
  sys_db: SystemDatabase, workflowUUID: str, getRequest: bool
133
132
  ) -> Optional[WorkflowInformation]:
dbos/cli.py CHANGED
@@ -9,6 +9,7 @@ from os import path
9
9
  from typing import Any
10
10
 
11
11
  import jsonpickle # type: ignore
12
+ import requests
12
13
  import sqlalchemy as sa
13
14
  import tomlkit
14
15
  import typer
@@ -22,12 +23,7 @@ from . import _serialization, load_config
22
23
  from ._app_db import ApplicationDatabase
23
24
  from ._dbos_config import _is_valid_app_name
24
25
  from ._sys_db import SystemDatabase
25
- from ._workflow_commands import (
26
- _cancel_workflow,
27
- _get_workflow,
28
- _list_workflows,
29
- _reattempt_workflow,
30
- )
26
+ from ._workflow_commands import _cancel_workflow, _get_workflow, _list_workflows
31
27
 
32
28
  app = typer.Typer()
33
29
  workflow = typer.Typer()
@@ -432,5 +428,49 @@ def cancel(
432
428
  print(f"Workflow {uuid} has been cancelled")
433
429
 
434
430
 
431
+ @workflow.command(help="Resume a workflow that has been cancelled")
432
+ def resume(
433
+ uuid: Annotated[str, typer.Argument()],
434
+ host: Annotated[
435
+ typing.Optional[str],
436
+ typer.Option("--host", "-h", help="Specify the admin host"),
437
+ ] = "localhost",
438
+ port: Annotated[
439
+ typing.Optional[int],
440
+ typer.Option("--port", "-p", help="Specify the admin port"),
441
+ ] = 3001,
442
+ ) -> None:
443
+ response = requests.post(
444
+ f"http://{host}:{port}/workflows/{uuid}/resume", json=[], timeout=5
445
+ )
446
+
447
+ if response.status_code == 200:
448
+ print(f"Workflow {uuid} has been resumed")
449
+ else:
450
+ print(f"Failed to resume workflow {uuid}. Status code: {response.status_code}")
451
+
452
+
453
+ @workflow.command(help="Restart a workflow from the beginning with a new id")
454
+ def restart(
455
+ uuid: Annotated[str, typer.Argument()],
456
+ host: Annotated[
457
+ typing.Optional[str],
458
+ typer.Option("--host", "-h", help="Specify the admin host"),
459
+ ] = "localhost",
460
+ port: Annotated[
461
+ typing.Optional[int],
462
+ typer.Option("--port", "-p", help="Specify the admin port"),
463
+ ] = 3001,
464
+ ) -> None:
465
+ response = requests.post(
466
+ f"http://{host}:{port}/workflows/{uuid}/restart", json=[], timeout=5
467
+ )
468
+
469
+ if response.status_code == 200:
470
+ print(f"Workflow {uuid} has been restarted")
471
+ else:
472
+ print(f"Failed to resume workflow {uuid}. Status code: {response.status_code}")
473
+
474
+
435
475
  if __name__ == "__main__":
436
476
  app()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dbos
3
- Version: 0.19.0a9
3
+ Version: 0.20.0a2
4
4
  Summary: Ultra-lightweight durable execution in Python
5
5
  Author-Email: "DBOS, Inc." <contact@dbos.dev>
6
6
  License: MIT
@@ -1,23 +1,23 @@
1
- dbos-0.19.0a9.dist-info/METADATA,sha256=5CSu4x-YJTciUZxrw786SNQb6SxB0aM7If4BlrwgG0U,5309
2
- dbos-0.19.0a9.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
- dbos-0.19.0a9.dist-info/entry_points.txt,sha256=z6GcVANQV7Uw_82H9Ob2axJX6V3imftyZsljdh-M1HU,54
4
- dbos-0.19.0a9.dist-info/licenses/LICENSE,sha256=VGZit_a5-kdw9WT6fY5jxAWVwGQzgLFyPWrcVVUhVNU,1067
1
+ dbos-0.20.0a2.dist-info/METADATA,sha256=HuHOltiSuDZN-RYCA22G-kTSVYlfK9bksxlPiAamZuo,5309
2
+ dbos-0.20.0a2.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
+ dbos-0.20.0a2.dist-info/entry_points.txt,sha256=z6GcVANQV7Uw_82H9Ob2axJX6V3imftyZsljdh-M1HU,54
4
+ dbos-0.20.0a2.dist-info/licenses/LICENSE,sha256=VGZit_a5-kdw9WT6fY5jxAWVwGQzgLFyPWrcVVUhVNU,1067
5
5
  dbos/__init__.py,sha256=CxRHBHEthPL4PZoLbZhp3rdm44-KkRTT2-7DkK9d4QQ,724
6
- dbos/_admin_server.py,sha256=DOgzVp9kmwiebQqmJB1LcrZnGTxSMbZiGXdenc1wZDg,3163
6
+ dbos/_admin_server.py,sha256=PJgneZG9-64TapZrPeJtt73puAswRImCE5uce2k2PKU,4750
7
7
  dbos/_app_db.py,sha256=_tv2vmPjjiaikwgxH3mqxgJ4nUUcG2-0uMXKWCqVu1c,5509
8
8
  dbos/_classproperty.py,sha256=f0X-_BySzn3yFDRKB2JpCbLYQ9tLwt1XftfshvY7CBs,626
9
9
  dbos/_cloudutils/authentication.py,sha256=V0fCWQN9stCkhbuuxgPTGpvuQcDqfU3KAxPAh01vKW4,5007
10
10
  dbos/_cloudutils/cloudutils.py,sha256=5e3CW1deSW-dI5G3QN0XbiVsBhyqT8wu7fuV2f8wtGU,7688
11
11
  dbos/_cloudutils/databases.py,sha256=x4187Djsyoa-QaG3Kog8JT2_GERsnqa93LIVanmVUmg,8393
12
12
  dbos/_context.py,sha256=RH08s_nee95vgxdz6AsYuVWF1LuJSVtOyIifblsa4pw,18760
13
- dbos/_core.py,sha256=lonD_iSnZtxhwetDcDlCV3HLr40jjqxUS2Q0TFaIOt0,34784
13
+ dbos/_core.py,sha256=dmVve1YZyQmAfwKsxqz6N3bXBowsMBmLxBDsymoWKsA,35956
14
14
  dbos/_croniter.py,sha256=hbhgfsHBqclUS8VeLnJ9PSE9Z54z6mi4nnrr1aUXn0k,47561
15
15
  dbos/_db_wizard.py,sha256=xgKLna0_6Xi50F3o8msRosXba8NScHlpJR5ICVCkHDQ,7534
16
- dbos/_dbos.py,sha256=LWFa48CPt7bsNAnMZrNDzHHTFCyMrY-nKbMZwCG_dqY,34710
16
+ dbos/_dbos.py,sha256=Kgnity6JxjThIf1L8CQbeobQMiJqUUeWlRf36_eGu2g,35385
17
17
  dbos/_dbos_config.py,sha256=h_q1gzudhsAMVkGMD0qQ6kLic6YhdJgzm50YFSIx9Bo,8196
18
18
  dbos/_error.py,sha256=vtaSsG0QW6cRlwfZ4zzZWy_IHCZlomwSlrDyGWuyn8c,4337
19
- dbos/_fastapi.py,sha256=iyefCZq-ZDKRUjN_rgYQmFmyvWf4gPrSlC6CLbfq4a8,3419
20
- dbos/_flask.py,sha256=z1cijbTi5Dpq6kqikPCx1LcR2YHHv2oc41NehOWjw74,2431
19
+ dbos/_fastapi.py,sha256=yRHrCwul2iYBxAAYuBQLcn9LMYUS6PE4CU9y1vUSPR8,3587
20
+ dbos/_flask.py,sha256=DZKUZR5-xOzPI7tYZ53r2PvvHVoAb8SYwLzMVFsVfjI,2608
21
21
  dbos/_kafka.py,sha256=o6DbwnsYRDtvVTZVsN7BAK8cdP79AfoWX3Q7CGY2Yuo,4199
22
22
  dbos/_kafka_message.py,sha256=NYvOXNG3Qn7bghn1pv3fg4Pbs86ILZGcK4IB-MLUNu0,409
23
23
  dbos/_logger.py,sha256=iYwbA7DLyXalWa2Yu07HO6Xm301nRuenMU64GgwUMkU,3576
@@ -53,9 +53,9 @@ dbos/_templates/hello/migrations/script.py.mako,sha256=MEqL-2qATlST9TAOeYgscMn1u
53
53
  dbos/_templates/hello/migrations/versions/2024_07_31_180642_init.py,sha256=U5thFWGqNN4QLrNXT7wUUqftIFDNE5eSdqD8JNW1mec,942
54
54
  dbos/_templates/hello/start_postgres_docker.py,sha256=lQVLlYO5YkhGPEgPqwGc7Y8uDKse9HsWv5fynJEFJHM,1681
55
55
  dbos/_tracer.py,sha256=rvBY1RQU6DO7rL7EnaJJxGcmd4tP_PpGqUEE6imZnhY,2518
56
- dbos/_workflow_commands.py,sha256=25mLcPifaaQtX_Wzrf2LVq4CtXGDjmLHABimTcOeQuw,4691
57
- dbos/cli.py,sha256=0E_QDJm3aGjjauUnmrsdZkqc8U49L6j2uPEtA0QRaZE,13946
56
+ dbos/_workflow_commands.py,sha256=tj-gJARjDJ5aYo0ii2udTAU4l36vbeXwmOYh8Q4y_ac,4625
57
+ dbos/cli.py,sha256=26fowBwpV-U7kuPdGRnAcuUMJIqYvstMX9qJ0t-B6BI,15354
58
58
  dbos/dbos-config.schema.json,sha256=X5TpXNcARGceX0zQs0fVgtZW_Xj9uBbY5afPt9Rz9yk,5741
59
59
  dbos/py.typed,sha256=QfzXT1Ktfk3Rj84akygc7_42z0lRpCq0Ilh8OXI6Zas,44
60
60
  version/__init__.py,sha256=L4sNxecRuqdtSFdpUGX3TtBi9KL3k7YsZVIvv-fv9-A,1678
61
- dbos-0.19.0a9.dist-info/RECORD,,
61
+ dbos-0.20.0a2.dist-info/RECORD,,