dbos 1.4.0a1__tar.gz → 1.5.0__tar.gz

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.
Files changed (108) hide show
  1. {dbos-1.4.0a1 → dbos-1.5.0}/PKG-INFO +1 -1
  2. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_admin_server.py +108 -2
  3. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_app_db.py +18 -0
  4. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_conductor/conductor.py +37 -0
  5. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_conductor/protocol.py +18 -0
  6. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_core.py +5 -5
  7. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_dbos.py +2 -2
  8. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_dbos_config.py +5 -2
  9. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_debug.py +4 -4
  10. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_error.py +5 -2
  11. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_logger.py +5 -2
  12. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_outcome.py +11 -7
  13. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_queue.py +0 -1
  14. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_recovery.py +4 -6
  15. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_sys_db.py +56 -0
  16. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_tracer.py +5 -0
  17. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_workflow_commands.py +35 -2
  18. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/cli/cli.py +31 -2
  19. {dbos-1.4.0a1 → dbos-1.5.0}/pyproject.toml +1 -1
  20. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_admin_server.py +197 -1
  21. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_config.py +21 -10
  22. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_failures.py +7 -1
  23. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_outcome.py +2 -2
  24. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_queue.py +54 -1
  25. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_spans.py +7 -2
  26. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_workflow_management.py +123 -1
  27. {dbos-1.4.0a1 → dbos-1.5.0}/LICENSE +0 -0
  28. {dbos-1.4.0a1 → dbos-1.5.0}/README.md +0 -0
  29. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/__init__.py +0 -0
  30. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/__main__.py +0 -0
  31. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_classproperty.py +0 -0
  32. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_client.py +0 -0
  33. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_context.py +0 -0
  34. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_croniter.py +0 -0
  35. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_docker_pg_helper.py +0 -0
  36. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_event_loop.py +0 -0
  37. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_fastapi.py +0 -0
  38. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_flask.py +0 -0
  39. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_kafka.py +0 -0
  40. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_kafka_message.py +0 -0
  41. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/env.py +0 -0
  42. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/script.py.mako +0 -0
  43. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/versions/04ca4f231047_workflow_queues_executor_id.py +0 -0
  44. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/versions/27ac6900c6ad_add_queue_dedup.py +0 -0
  45. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/versions/50f3227f0b4b_fix_job_queue.py +0 -0
  46. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/versions/5c361fc04708_added_system_tables.py +0 -0
  47. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/versions/66478e1b95e5_consolidate_queues.py +0 -0
  48. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/versions/83f3732ae8e7_workflow_timeout.py +0 -0
  49. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/versions/933e86bdac6a_add_queue_priority.py +0 -0
  50. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/versions/a3b18ad34abe_added_triggers.py +0 -0
  51. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/versions/d76646551a6b_job_queue_limiter.py +0 -0
  52. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/versions/d76646551a6c_workflow_queue.py +0 -0
  53. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/versions/d994145b47b6_consolidate_inputs.py +0 -0
  54. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/versions/eab0cc1d9a14_job_queue.py +0 -0
  55. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_migrations/versions/f4b9b32ba814_functionname_childid_op_outputs.py +0 -0
  56. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_registrations.py +0 -0
  57. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_roles.py +0 -0
  58. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_scheduler.py +0 -0
  59. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_schemas/__init__.py +0 -0
  60. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_schemas/application_database.py +0 -0
  61. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_schemas/system_database.py +0 -0
  62. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_serialization.py +0 -0
  63. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_templates/dbos-db-starter/README.md +0 -0
  64. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_templates/dbos-db-starter/__package/__init__.py +0 -0
  65. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_templates/dbos-db-starter/__package/main.py.dbos +0 -0
  66. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_templates/dbos-db-starter/__package/schema.py +0 -0
  67. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_templates/dbos-db-starter/alembic.ini +0 -0
  68. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_templates/dbos-db-starter/dbos-config.yaml.dbos +0 -0
  69. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_templates/dbos-db-starter/migrations/env.py.dbos +0 -0
  70. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_templates/dbos-db-starter/migrations/script.py.mako +0 -0
  71. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_templates/dbos-db-starter/migrations/versions/2024_07_31_180642_init.py +0 -0
  72. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_templates/dbos-db-starter/start_postgres_docker.py +0 -0
  73. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/_utils.py +0 -0
  74. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/cli/_github_init.py +0 -0
  75. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/cli/_template_init.py +0 -0
  76. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/dbos-config.schema.json +0 -0
  77. {dbos-1.4.0a1 → dbos-1.5.0}/dbos/py.typed +0 -0
  78. {dbos-1.4.0a1 → dbos-1.5.0}/tests/__init__.py +0 -0
  79. {dbos-1.4.0a1 → dbos-1.5.0}/tests/atexit_no_ctor.py +0 -0
  80. {dbos-1.4.0a1 → dbos-1.5.0}/tests/atexit_no_launch.py +0 -0
  81. {dbos-1.4.0a1 → dbos-1.5.0}/tests/classdefs.py +0 -0
  82. {dbos-1.4.0a1 → dbos-1.5.0}/tests/client_collateral.py +0 -0
  83. {dbos-1.4.0a1 → dbos-1.5.0}/tests/client_worker.py +0 -0
  84. {dbos-1.4.0a1 → dbos-1.5.0}/tests/conftest.py +0 -0
  85. {dbos-1.4.0a1 → dbos-1.5.0}/tests/dupname_classdefs1.py +0 -0
  86. {dbos-1.4.0a1 → dbos-1.5.0}/tests/dupname_classdefsa.py +0 -0
  87. {dbos-1.4.0a1 → dbos-1.5.0}/tests/more_classdefs.py +0 -0
  88. {dbos-1.4.0a1 → dbos-1.5.0}/tests/queuedworkflow.py +0 -0
  89. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_async.py +0 -0
  90. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_classdecorators.py +0 -0
  91. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_cli.py +0 -0
  92. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_client.py +0 -0
  93. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_concurrency.py +0 -0
  94. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_croniter.py +0 -0
  95. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_dbos.py +0 -0
  96. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_debug.py +0 -0
  97. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_docker_secrets.py +0 -0
  98. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_fastapi.py +0 -0
  99. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_fastapi_roles.py +0 -0
  100. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_flask.py +0 -0
  101. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_kafka.py +0 -0
  102. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_package.py +0 -0
  103. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_scheduler.py +0 -0
  104. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_schema_migration.py +0 -0
  105. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_singleton.py +0 -0
  106. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_sqlalchemy.py +0 -0
  107. {dbos-1.4.0a1 → dbos-1.5.0}/tests/test_workflow_introspection.py +0 -0
  108. {dbos-1.4.0a1 → dbos-1.5.0}/version/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dbos
3
- Version: 1.4.0a1
3
+ Version: 1.5.0
4
4
  Summary: Ultra-lightweight durable execution in Python
5
5
  Author-Email: "DBOS, Inc." <contact@dbos.dev>
6
6
  License: MIT
@@ -5,7 +5,9 @@ import re
5
5
  import threading
6
6
  from functools import partial
7
7
  from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
8
- from typing import TYPE_CHECKING, Any, List, Optional, TypedDict
8
+ from typing import TYPE_CHECKING, Any, Dict, List, Optional, TypedDict
9
+
10
+ from dbos._workflow_commands import garbage_collect, global_timeout
9
11
 
10
12
  from ._context import SetWorkflowID
11
13
  from ._error import DBOSException
@@ -20,6 +22,10 @@ _health_check_path = "/dbos-healthz"
20
22
  _workflow_recovery_path = "/dbos-workflow-recovery"
21
23
  _deactivate_path = "/deactivate"
22
24
  _workflow_queues_metadata_path = "/dbos-workflow-queues-metadata"
25
+ _garbage_collect_path = "/dbos-garbage-collect"
26
+ _global_timeout_path = "/dbos-global-timeout"
27
+ _queued_workflows_path = "/queues"
28
+ _workflows_path = "/workflows"
23
29
  # /workflows/:workflow_id/cancel
24
30
  # /workflows/:workflow_id/resume
25
31
  # /workflows/:workflow_id/restart
@@ -100,10 +106,24 @@ class AdminRequestHandler(BaseHTTPRequestHandler):
100
106
  steps_match = re.match(
101
107
  r"^/workflows/(?P<workflow_id>[^/]+)/steps$", self.path
102
108
  )
109
+ workflow_match = re.match(r"^/workflows/(?P<workflow_id>[^/]+)$", self.path)
103
110
 
104
111
  if steps_match:
105
112
  workflow_id = steps_match.group("workflow_id")
106
113
  self._handle_steps(workflow_id)
114
+ elif workflow_match:
115
+ workflow_id = workflow_match.group("workflow_id")
116
+ workflows = self.dbos.list_workflows(workflow_ids=[workflow_id])
117
+ if not workflows:
118
+ self.send_response(404)
119
+ self._end_headers()
120
+ return
121
+ response_body = json.dumps(workflows[0].__dict__).encode("utf-8")
122
+ self.send_response(200)
123
+ self.send_header("Content-Type", "application/json")
124
+ self.send_header("Content-Length", str(len(response_body)))
125
+ self._end_headers()
126
+ self.wfile.write(response_body)
107
127
  else:
108
128
  self.send_response(404)
109
129
  self._end_headers()
@@ -122,8 +142,50 @@ class AdminRequestHandler(BaseHTTPRequestHandler):
122
142
  self.send_response(200)
123
143
  self._end_headers()
124
144
  self.wfile.write(json.dumps(workflow_ids).encode("utf-8"))
145
+ elif self.path == _workflows_path:
146
+ try:
147
+ filters = json.loads(post_data.decode("utf-8")) if post_data else {}
148
+ self._handle_workflows(filters)
149
+ except (json.JSONDecodeError, AttributeError) as e:
150
+ self.send_response(400)
151
+ self.send_header("Content-Type", "application/json")
152
+ self.end_headers()
153
+ self.wfile.write(
154
+ json.dumps({"error": f"Invalid JSON input: {str(e)}"}).encode(
155
+ "utf-8"
156
+ )
157
+ )
158
+ elif self.path == _queued_workflows_path:
159
+ try:
160
+ filters = json.loads(post_data.decode("utf-8")) if post_data else {}
161
+ self._handle_queued_workflows(filters)
162
+ except (json.JSONDecodeError, AttributeError) as e:
163
+ self.send_response(400)
164
+ self.send_header("Content-Type", "application/json")
165
+ self.end_headers()
166
+ self.wfile.write(
167
+ json.dumps({"error": f"Invalid JSON input: {str(e)}"}).encode(
168
+ "utf-8"
169
+ )
170
+ )
171
+ elif self.path == _garbage_collect_path:
172
+ inputs = json.loads(post_data.decode("utf-8"))
173
+ cutoff_epoch_timestamp_ms = inputs.get("cutoff_epoch_timestamp_ms", None)
174
+ rows_threshold = inputs.get("rows_threshold", None)
175
+ garbage_collect(
176
+ self.dbos,
177
+ cutoff_epoch_timestamp_ms=cutoff_epoch_timestamp_ms,
178
+ rows_threshold=rows_threshold,
179
+ )
180
+ self.send_response(204)
181
+ self._end_headers()
182
+ elif self.path == _global_timeout_path:
183
+ inputs = json.loads(post_data.decode("utf-8"))
184
+ cutoff_epoch_timestamp_ms = inputs.get("cutoff_epoch_timestamp_ms", None)
185
+ global_timeout(self.dbos, cutoff_epoch_timestamp_ms)
186
+ self.send_response(204)
187
+ self._end_headers()
125
188
  else:
126
-
127
189
  restart_match = re.match(
128
190
  r"^/workflows/(?P<workflow_id>[^/]+)/restart$", self.path
129
191
  )
@@ -262,6 +324,50 @@ class AdminRequestHandler(BaseHTTPRequestHandler):
262
324
  self._end_headers()
263
325
  self.wfile.write(json_steps)
264
326
 
327
+ def _handle_workflows(self, filters: Dict[str, Any]) -> None:
328
+ workflows = self.dbos.list_workflows(
329
+ workflow_ids=filters.get("workflow_ids"),
330
+ name=filters.get("name"),
331
+ start_time=filters.get("start_time"),
332
+ end_time=filters.get("end_time"),
333
+ status=filters.get("status"),
334
+ app_version=filters.get("application_version"),
335
+ limit=filters.get("limit"),
336
+ offset=filters.get("offset"),
337
+ sort_desc=filters.get("sort_desc", False),
338
+ workflow_id_prefix=filters.get("workflow_id_prefix"),
339
+ )
340
+
341
+ response_body = json.dumps(
342
+ [workflow.__dict__ for workflow in workflows]
343
+ ).encode("utf-8")
344
+ self.send_response(200)
345
+ self.send_header("Content-Type", "application/json")
346
+ self.send_header("Content-Length", str(len(response_body)))
347
+ self._end_headers()
348
+ self.wfile.write(response_body)
349
+
350
+ def _handle_queued_workflows(self, filters: Dict[str, Any]) -> None:
351
+ workflows = self.dbos.list_queued_workflows(
352
+ queue_name=filters.get("queue_name"),
353
+ name=filters.get("name"),
354
+ start_time=filters.get("start_time"),
355
+ end_time=filters.get("end_time"),
356
+ status=filters.get("status"),
357
+ limit=filters.get("limit"),
358
+ offset=filters.get("offset"),
359
+ sort_desc=filters.get("sort_desc", False),
360
+ )
361
+
362
+ response_body = json.dumps(
363
+ [workflow.__dict__ for workflow in workflows]
364
+ ).encode("utf-8")
365
+ self.send_response(200)
366
+ self.send_header("Content-Type", "application/json")
367
+ self.send_header("Content-Length", str(len(response_body)))
368
+ self._end_headers()
369
+ self.wfile.write(response_body)
370
+
265
371
 
266
372
  # Be consistent with DBOS-TS response.
267
373
  class PerfUtilization(TypedDict):
@@ -256,3 +256,21 @@ class ApplicationDatabase:
256
256
  )
257
257
 
258
258
  conn.execute(insert_stmt)
259
+
260
+ def garbage_collect(
261
+ self, cutoff_epoch_timestamp_ms: int, pending_workflow_ids: list[str]
262
+ ) -> None:
263
+ with self.engine.begin() as c:
264
+ delete_query = sa.delete(ApplicationSchema.transaction_outputs).where(
265
+ ApplicationSchema.transaction_outputs.c.created_at
266
+ < cutoff_epoch_timestamp_ms
267
+ )
268
+
269
+ if len(pending_workflow_ids) > 0:
270
+ delete_query = delete_query.where(
271
+ ~ApplicationSchema.transaction_outputs.c.workflow_uuid.in_(
272
+ pending_workflow_ids
273
+ )
274
+ )
275
+
276
+ c.execute(delete_query)
@@ -13,7 +13,9 @@ from websockets.sync.connection import Connection
13
13
  from dbos._context import SetWorkflowID
14
14
  from dbos._utils import GlobalParams
15
15
  from dbos._workflow_commands import (
16
+ garbage_collect,
16
17
  get_workflow,
18
+ global_timeout,
17
19
  list_queued_workflows,
18
20
  list_workflow_steps,
19
21
  list_workflows,
@@ -356,6 +358,41 @@ class ConductorWebsocket(threading.Thread):
356
358
  error_message=error_message,
357
359
  )
358
360
  websocket.send(list_steps_response.to_json())
361
+ elif msg_type == p.MessageType.RETENTION:
362
+ retention_message = p.RetentionRequest.from_json(message)
363
+ success = True
364
+ try:
365
+ garbage_collect(
366
+ self.dbos,
367
+ cutoff_epoch_timestamp_ms=retention_message.body[
368
+ "gc_cutoff_epoch_ms"
369
+ ],
370
+ rows_threshold=retention_message.body[
371
+ "gc_rows_threshold"
372
+ ],
373
+ )
374
+ if (
375
+ retention_message.body["timeout_cutoff_epoch_ms"]
376
+ is not None
377
+ ):
378
+ global_timeout(
379
+ self.dbos,
380
+ retention_message.body[
381
+ "timeout_cutoff_epoch_ms"
382
+ ],
383
+ )
384
+ except Exception as e:
385
+ error_message = f"Exception encountered during enforcing retention policy: {traceback.format_exc()}"
386
+ self.dbos.logger.error(error_message)
387
+ success = False
388
+
389
+ retention_response = p.RetentionResponse(
390
+ type=p.MessageType.RETENTION,
391
+ request_id=base_message.request_id,
392
+ success=success,
393
+ error_message=error_message,
394
+ )
395
+ websocket.send(retention_response.to_json())
359
396
  else:
360
397
  self.dbos.logger.warning(
361
398
  f"Unexpected message type: {msg_type}"
@@ -18,6 +18,7 @@ class MessageType(str, Enum):
18
18
  EXIST_PENDING_WORKFLOWS = "exist_pending_workflows"
19
19
  LIST_STEPS = "list_steps"
20
20
  FORK_WORKFLOW = "fork_workflow"
21
+ RETENTION = "retention"
21
22
 
22
23
 
23
24
  T = TypeVar("T", bound="BaseMessage")
@@ -280,3 +281,20 @@ class ForkWorkflowRequest(BaseMessage):
280
281
  class ForkWorkflowResponse(BaseMessage):
281
282
  new_workflow_id: Optional[str]
282
283
  error_message: Optional[str] = None
284
+
285
+
286
+ class RetentionBody(TypedDict):
287
+ gc_cutoff_epoch_ms: Optional[int]
288
+ gc_rows_threshold: Optional[int]
289
+ timeout_cutoff_epoch_ms: Optional[int]
290
+
291
+
292
+ @dataclass
293
+ class RetentionRequest(BaseMessage):
294
+ body: RetentionBody
295
+
296
+
297
+ @dataclass
298
+ class RetentionResponse(BaseMessage):
299
+ success: bool
300
+ error_message: Optional[str] = None
@@ -404,9 +404,9 @@ def _execute_workflow_wthread(
404
404
  return dbos._background_event_loop.submit_coroutine(
405
405
  cast(Pending[R], result)()
406
406
  )
407
- except Exception:
407
+ except Exception as e:
408
408
  dbos.logger.error(
409
- f"Exception encountered in asynchronous workflow: {traceback.format_exc()}"
409
+ f"Exception encountered in asynchronous workflow:", exc_info=e
410
410
  )
411
411
  raise
412
412
 
@@ -430,9 +430,9 @@ async def _execute_workflow_async(
430
430
  _get_wf_invoke_func(dbos, status)
431
431
  )
432
432
  return await result()
433
- except Exception:
433
+ except Exception as e:
434
434
  dbos.logger.error(
435
- f"Exception encountered in asynchronous workflow: {traceback.format_exc()}"
435
+ f"Exception encountered in asynchronous workflow:", exc_info=e
436
436
  )
437
437
  raise
438
438
 
@@ -1123,7 +1123,7 @@ def decorate_step(
1123
1123
  stepOutcome = stepOutcome.retry(
1124
1124
  max_attempts,
1125
1125
  on_exception,
1126
- lambda i: DBOSMaxStepRetriesExceeded(func.__name__, i),
1126
+ lambda i, e: DBOSMaxStepRetriesExceeded(func.__name__, i, e),
1127
1127
  )
1128
1128
 
1129
1129
  outcome = (
@@ -521,8 +521,8 @@ class DBOS:
521
521
  handler.flush()
522
522
  add_otlp_to_all_loggers()
523
523
  add_transformer_to_all_loggers()
524
- except Exception:
525
- dbos_logger.error(f"DBOS failed to launch: {traceback.format_exc()}")
524
+ except Exception as e:
525
+ dbos_logger.error(f"DBOS failed to launch:", exc_info=e)
526
526
  raise
527
527
 
528
528
  @classmethod
@@ -31,6 +31,7 @@ class DBOSConfig(TypedDict, total=False):
31
31
  otlp_logs_endpoints: List[str]: OTLP logs endpoints
32
32
  admin_port (int): Admin port
33
33
  run_admin_server (bool): Whether to run the DBOS admin server
34
+ otlp_attributes (dict[str, str]): A set of custom attributes to apply OTLP-exported logs and traces
34
35
  """
35
36
 
36
37
  name: str
@@ -43,6 +44,7 @@ class DBOSConfig(TypedDict, total=False):
43
44
  otlp_logs_endpoints: Optional[List[str]]
44
45
  admin_port: Optional[int]
45
46
  run_admin_server: Optional[bool]
47
+ otlp_attributes: Optional[dict[str, str]]
46
48
 
47
49
 
48
50
  class RuntimeConfig(TypedDict, total=False):
@@ -84,6 +86,7 @@ class LoggerConfig(TypedDict, total=False):
84
86
  class TelemetryConfig(TypedDict, total=False):
85
87
  logs: Optional[LoggerConfig]
86
88
  OTLPExporter: Optional[OTLPExporterConfig]
89
+ otlp_attributes: Optional[dict[str, str]]
87
90
 
88
91
 
89
92
  class ConfigFile(TypedDict, total=False):
@@ -145,7 +148,8 @@ def translate_dbos_config_to_config_file(config: DBOSConfig) -> ConfigFile:
145
148
 
146
149
  # Telemetry config
147
150
  telemetry: TelemetryConfig = {
148
- "OTLPExporter": {"tracesEndpoint": [], "logsEndpoint": []}
151
+ "OTLPExporter": {"tracesEndpoint": [], "logsEndpoint": []},
152
+ "otlp_attributes": config.get("otlp_attributes", {}),
149
153
  }
150
154
  # For mypy
151
155
  assert telemetry["OTLPExporter"] is not None
@@ -431,7 +435,6 @@ def is_valid_database_url(database_url: str) -> bool:
431
435
  url = make_url(database_url)
432
436
  required_fields = [
433
437
  ("username", "Username must be specified in the connection URL"),
434
- ("password", "Password must be specified in the connection URL"),
435
438
  ("host", "Host must be specified in the connection URL"),
436
439
  ("database", "Database name must be specified in the connection URL"),
437
440
  ]
@@ -15,11 +15,11 @@ class PythonModule:
15
15
 
16
16
 
17
17
  def debug_workflow(workflow_id: str, entrypoint: Union[str, PythonModule]) -> None:
18
- # include the current directory (represented by empty string) in the search path
19
- # if it not already included
20
- if "" not in sys.path:
21
- sys.path.insert(0, "")
22
18
  if isinstance(entrypoint, str):
19
+ # ensure the entrypoint parent directory is in sys.path
20
+ parent = str(Path(entrypoint).parent)
21
+ if parent not in sys.path:
22
+ sys.path.insert(0, parent)
23
23
  runpy.run_path(entrypoint)
24
24
  elif isinstance(entrypoint, PythonModule):
25
25
  runpy.run_module(entrypoint.module_name)
@@ -150,9 +150,12 @@ class DBOSNotAuthorizedError(DBOSException):
150
150
  class DBOSMaxStepRetriesExceeded(DBOSException):
151
151
  """Exception raised when a step was retried the maximimum number of times without success."""
152
152
 
153
- def __init__(self, step_name: str, max_retries: int) -> None:
153
+ def __init__(
154
+ self, step_name: str, max_retries: int, errors: list[Exception]
155
+ ) -> None:
154
156
  self.step_name = step_name
155
157
  self.max_retries = max_retries
158
+ self.errors = errors
156
159
  super().__init__(
157
160
  f"Step {step_name} has exceeded its maximum of {max_retries} retries",
158
161
  dbos_error_code=DBOSErrorCode.MaxStepRetriesExceeded.value,
@@ -160,7 +163,7 @@ class DBOSMaxStepRetriesExceeded(DBOSException):
160
163
 
161
164
  def __reduce__(self) -> Any:
162
165
  # Tell jsonpickle how to reconstruct this object
163
- return (self.__class__, (self.step_name, self.max_retries))
166
+ return (self.__class__, (self.step_name, self.max_retries, self.errors))
164
167
 
165
168
 
166
169
  class DBOSConflictingRegistrationError(DBOSException):
@@ -20,14 +20,17 @@ _otlp_handler, _dbos_log_transformer = None, None
20
20
 
21
21
 
22
22
  class DBOSLogTransformer(logging.Filter):
23
- def __init__(self) -> None:
23
+ def __init__(self, config: "ConfigFile") -> None:
24
24
  super().__init__()
25
25
  self.app_id = os.environ.get("DBOS__APPID", "")
26
+ self.otlp_attributes: dict[str, str] = config.get("telemetry", {}).get("otlp_attributes", {}) # type: ignore
26
27
 
27
28
  def filter(self, record: Any) -> bool:
28
29
  record.applicationID = self.app_id
29
30
  record.applicationVersion = GlobalParams.app_version
30
31
  record.executorID = GlobalParams.executor_id
32
+ for k, v in self.otlp_attributes.items():
33
+ setattr(record, k, v)
31
34
 
32
35
  # If available, decorate the log entry with Workflow ID and Trace ID
33
36
  from dbos._context import get_local_dbos_context
@@ -98,7 +101,7 @@ def config_logger(config: "ConfigFile") -> None:
98
101
 
99
102
  # Attach DBOS-specific attributes to all log entries.
100
103
  global _dbos_log_transformer
101
- _dbos_log_transformer = DBOSLogTransformer()
104
+ _dbos_log_transformer = DBOSLogTransformer(config)
102
105
  dbos_logger.addFilter(_dbos_log_transformer)
103
106
 
104
107
 
@@ -37,7 +37,7 @@ class Outcome(Protocol[T]):
37
37
  self,
38
38
  attempts: int,
39
39
  on_exception: Callable[[int, BaseException], float],
40
- exceeded_retries: Callable[[int], BaseException],
40
+ exceeded_retries: Callable[[int, list[Exception]], Exception],
41
41
  ) -> "Outcome[T]": ...
42
42
 
43
43
  def intercept(
@@ -96,23 +96,25 @@ class Immediate(Outcome[T]):
96
96
  func: Callable[[], T],
97
97
  attempts: int,
98
98
  on_exception: Callable[[int, BaseException], float],
99
- exceeded_retries: Callable[[int], BaseException],
99
+ exceeded_retries: Callable[[int, list[Exception]], Exception],
100
100
  ) -> T:
101
+ errors: list[Exception] = []
101
102
  for i in range(attempts):
102
103
  try:
103
104
  with EnterDBOSStepRetry(i, attempts):
104
105
  return func()
105
106
  except Exception as exp:
107
+ errors.append(exp)
106
108
  wait_time = on_exception(i, exp)
107
109
  time.sleep(wait_time)
108
110
 
109
- raise exceeded_retries(attempts)
111
+ raise exceeded_retries(attempts, errors)
110
112
 
111
113
  def retry(
112
114
  self,
113
115
  attempts: int,
114
116
  on_exception: Callable[[int, BaseException], float],
115
- exceeded_retries: Callable[[int], BaseException],
117
+ exceeded_retries: Callable[[int, list[Exception]], Exception],
116
118
  ) -> "Immediate[T]":
117
119
  assert attempts > 0
118
120
  return Immediate[T](
@@ -183,23 +185,25 @@ class Pending(Outcome[T]):
183
185
  func: Callable[[], Coroutine[Any, Any, T]],
184
186
  attempts: int,
185
187
  on_exception: Callable[[int, BaseException], float],
186
- exceeded_retries: Callable[[int], BaseException],
188
+ exceeded_retries: Callable[[int, list[Exception]], Exception],
187
189
  ) -> T:
190
+ errors: list[Exception] = []
188
191
  for i in range(attempts):
189
192
  try:
190
193
  with EnterDBOSStepRetry(i, attempts):
191
194
  return await func()
192
195
  except Exception as exp:
196
+ errors.append(exp)
193
197
  wait_time = on_exception(i, exp)
194
198
  await asyncio.sleep(wait_time)
195
199
 
196
- raise exceeded_retries(attempts)
200
+ raise exceeded_retries(attempts, errors)
197
201
 
198
202
  def retry(
199
203
  self,
200
204
  attempts: int,
201
205
  on_exception: Callable[[int, BaseException], float],
202
- exceeded_retries: Callable[[int], BaseException],
206
+ exceeded_retries: Callable[[int, list[Exception]], Exception],
203
207
  ) -> "Pending[T]":
204
208
  assert attempts > 0
205
209
  return Pending[T](
@@ -1,5 +1,4 @@
1
1
  import threading
2
- import traceback
3
2
  from typing import TYPE_CHECKING, Any, Callable, Coroutine, Optional, TypedDict
4
3
 
5
4
  from psycopg import errors
@@ -1,7 +1,5 @@
1
- import os
2
1
  import threading
3
2
  import time
4
- import traceback
5
3
  from typing import TYPE_CHECKING, Any, List
6
4
 
7
5
  from dbos._utils import GlobalParams
@@ -39,9 +37,9 @@ def startup_recovery_thread(
39
37
  time.sleep(1)
40
38
  except Exception as e:
41
39
  dbos.logger.error(
42
- f"Exception encountered when recovering workflows: {traceback.format_exc()}"
40
+ f"Exception encountered when recovering workflows:", exc_info=e
43
41
  )
44
- raise e
42
+ raise
45
43
 
46
44
 
47
45
  def recover_pending_workflows(
@@ -59,9 +57,9 @@ def recover_pending_workflows(
59
57
  workflow_handles.append(handle)
60
58
  except Exception as e:
61
59
  dbos.logger.error(
62
- f"Exception encountered when recovering workflows: {traceback.format_exc()}"
60
+ f"Exception encountered when recovering workflows:", exc_info=e
63
61
  )
64
- raise e
62
+ raise
65
63
  dbos.logger.info(
66
64
  f"Recovering {len(pending_workflows)} workflows for executor {executor_id} from version {GlobalParams.app_version}"
67
65
  )
@@ -1852,6 +1852,62 @@ class SystemDatabase:
1852
1852
  dbos_logger.error(f"Error connecting to the DBOS system database: {e}")
1853
1853
  raise
1854
1854
 
1855
+ def garbage_collect(
1856
+ self, cutoff_epoch_timestamp_ms: Optional[int], rows_threshold: Optional[int]
1857
+ ) -> Optional[tuple[int, list[str]]]:
1858
+ if rows_threshold is not None:
1859
+ with self.engine.begin() as c:
1860
+ # Get the created_at timestamp of the rows_threshold newest row
1861
+ result = c.execute(
1862
+ sa.select(SystemSchema.workflow_status.c.created_at)
1863
+ .order_by(SystemSchema.workflow_status.c.created_at.desc())
1864
+ .limit(1)
1865
+ .offset(rows_threshold - 1)
1866
+ ).fetchone()
1867
+
1868
+ if result is not None:
1869
+ rows_based_cutoff = result[0]
1870
+ # Use the more restrictive cutoff (higher timestamp = more recent = more deletion)
1871
+ if (
1872
+ cutoff_epoch_timestamp_ms is None
1873
+ or rows_based_cutoff > cutoff_epoch_timestamp_ms
1874
+ ):
1875
+ cutoff_epoch_timestamp_ms = rows_based_cutoff
1876
+
1877
+ if cutoff_epoch_timestamp_ms is None:
1878
+ return None
1879
+
1880
+ with self.engine.begin() as c:
1881
+ # Delete all workflows older than cutoff that are NOT PENDING or ENQUEUED
1882
+ c.execute(
1883
+ sa.delete(SystemSchema.workflow_status)
1884
+ .where(
1885
+ SystemSchema.workflow_status.c.created_at
1886
+ < cutoff_epoch_timestamp_ms
1887
+ )
1888
+ .where(
1889
+ ~SystemSchema.workflow_status.c.status.in_(
1890
+ [
1891
+ WorkflowStatusString.PENDING.value,
1892
+ WorkflowStatusString.ENQUEUED.value,
1893
+ ]
1894
+ )
1895
+ )
1896
+ )
1897
+
1898
+ # Then, get the IDs of all remaining old workflows
1899
+ pending_enqueued_result = c.execute(
1900
+ sa.select(SystemSchema.workflow_status.c.workflow_uuid).where(
1901
+ SystemSchema.workflow_status.c.created_at
1902
+ < cutoff_epoch_timestamp_ms
1903
+ )
1904
+ ).fetchall()
1905
+
1906
+ # Return the final cutoff and workflow IDs
1907
+ return cutoff_epoch_timestamp_ms, [
1908
+ row[0] for row in pending_enqueued_result
1909
+ ]
1910
+
1855
1911
 
1856
1912
  def reset_system_database(postgres_db_url: sa.URL, sysdb_name: str) -> None:
1857
1913
  try:
@@ -19,11 +19,14 @@ if TYPE_CHECKING:
19
19
 
20
20
  class DBOSTracer:
21
21
 
22
+ otlp_attributes: dict[str, str] = {}
23
+
22
24
  def __init__(self) -> None:
23
25
  self.app_id = os.environ.get("DBOS__APPID", None)
24
26
  self.provider: Optional[TracerProvider] = None
25
27
 
26
28
  def config(self, config: ConfigFile) -> None:
29
+ self.otlp_attributes = config.get("telemetry", {}).get("otlp_attributes", {}) # type: ignore
27
30
  if not isinstance(trace.get_tracer_provider(), TracerProvider):
28
31
  resource = Resource(
29
32
  attributes={
@@ -63,6 +66,8 @@ class DBOSTracer:
63
66
  for k, v in attributes.items():
64
67
  if k != "name" and v is not None and isinstance(v, (str, bool, int, float)):
65
68
  span.set_attribute(k, v)
69
+ for k, v in self.otlp_attributes.items():
70
+ span.set_attribute(k, v)
66
71
  return span
67
72
 
68
73
  def end_span(self, span: Span) -> None:
@@ -1,8 +1,9 @@
1
+ import time
1
2
  import uuid
2
- from typing import List, Optional
3
+ from datetime import datetime
4
+ from typing import TYPE_CHECKING, List, Optional
3
5
 
4
6
  from dbos._context import get_local_dbos_context
5
- from dbos._error import DBOSException
6
7
 
7
8
  from ._app_db import ApplicationDatabase
8
9
  from ._sys_db import (
@@ -11,8 +12,12 @@ from ._sys_db import (
11
12
  StepInfo,
12
13
  SystemDatabase,
13
14
  WorkflowStatus,
15
+ WorkflowStatusString,
14
16
  )
15
17
 
18
+ if TYPE_CHECKING:
19
+ from ._dbos import DBOS
20
+
16
21
 
17
22
  def list_workflows(
18
23
  sys_db: SystemDatabase,
@@ -118,3 +123,31 @@ def fork_workflow(
118
123
  application_version=application_version,
119
124
  )
120
125
  return forked_workflow_id
126
+
127
+
128
+ def garbage_collect(
129
+ dbos: "DBOS",
130
+ cutoff_epoch_timestamp_ms: Optional[int],
131
+ rows_threshold: Optional[int],
132
+ ) -> None:
133
+ if cutoff_epoch_timestamp_ms is None and rows_threshold is None:
134
+ return
135
+ result = dbos._sys_db.garbage_collect(
136
+ cutoff_epoch_timestamp_ms=cutoff_epoch_timestamp_ms,
137
+ rows_threshold=rows_threshold,
138
+ )
139
+ if result is not None:
140
+ cutoff_epoch_timestamp_ms, pending_workflow_ids = result
141
+ dbos._app_db.garbage_collect(cutoff_epoch_timestamp_ms, pending_workflow_ids)
142
+
143
+
144
+ def global_timeout(dbos: "DBOS", cutoff_epoch_timestamp_ms: int) -> None:
145
+ cutoff_iso = datetime.fromtimestamp(cutoff_epoch_timestamp_ms / 1000).isoformat()
146
+ for workflow in dbos.list_workflows(
147
+ status=WorkflowStatusString.PENDING.value, end_time=cutoff_iso
148
+ ):
149
+ dbos.cancel_workflow(workflow.workflow_id)
150
+ for workflow in dbos.list_workflows(
151
+ status=WorkflowStatusString.ENQUEUED.value, end_time=cutoff_iso
152
+ ):
153
+ dbos.cancel_workflow(workflow.workflow_id)