dbos 0.22.0a10__py3-none-any.whl → 0.23.0__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/_recovery.py CHANGED
@@ -4,6 +4,8 @@ import time
4
4
  import traceback
5
5
  from typing import TYPE_CHECKING, Any, List
6
6
 
7
+ from dbos._utils import GlobalParams
8
+
7
9
  from ._core import execute_workflow_by_id
8
10
  from ._error import DBOSWorkflowFunctionNotFoundError
9
11
  from ._sys_db import GetPendingWorkflowsOutput
@@ -12,6 +14,16 @@ if TYPE_CHECKING:
12
14
  from ._dbos import DBOS, WorkflowHandle
13
15
 
14
16
 
17
+ def _recover_workflow(
18
+ dbos: "DBOS", workflow: GetPendingWorkflowsOutput
19
+ ) -> "WorkflowHandle[Any]":
20
+ if workflow.queue_name and workflow.queue_name != "_dbos_internal_queue":
21
+ cleared = dbos._sys_db.clear_queue_assignment(workflow.workflow_uuid)
22
+ if cleared:
23
+ return dbos.retrieve_workflow(workflow.workflow_uuid)
24
+ return execute_workflow_by_id(dbos, workflow.workflow_uuid)
25
+
26
+
15
27
  def startup_recovery_thread(
16
28
  dbos: "DBOS", pending_workflows: List[GetPendingWorkflowsOutput]
17
29
  ) -> None:
@@ -21,13 +33,7 @@ def startup_recovery_thread(
21
33
  while not stop_event.is_set() and len(pending_workflows) > 0:
22
34
  try:
23
35
  for pending_workflow in list(pending_workflows):
24
- if (
25
- pending_workflow.queue_name
26
- and pending_workflow.queue_name != "_dbos_internal_queue"
27
- ):
28
- dbos._sys_db.clear_queue_assignment(pending_workflow.workflow_uuid)
29
- continue
30
- execute_workflow_by_id(dbos, pending_workflow.workflow_uuid)
36
+ _recover_workflow(dbos, pending_workflow)
31
37
  pending_workflows.remove(pending_workflow)
32
38
  except DBOSWorkflowFunctionNotFoundError:
33
39
  time.sleep(1)
@@ -41,29 +47,22 @@ def startup_recovery_thread(
41
47
  def recover_pending_workflows(
42
48
  dbos: "DBOS", executor_ids: List[str] = ["local"]
43
49
  ) -> List["WorkflowHandle[Any]"]:
50
+ """Attempt to recover pending workflows for a list of specific executors and return workflow handles for them."""
44
51
  workflow_handles: List["WorkflowHandle[Any]"] = []
45
52
  for executor_id in executor_ids:
46
- dbos.logger.debug(f"Recovering pending workflows for executor: {executor_id}")
47
53
  pending_workflows = dbos._sys_db.get_pending_workflows(
48
- executor_id, dbos.app_version
54
+ executor_id, GlobalParams.app_version
49
55
  )
50
56
  for pending_workflow in pending_workflows:
51
- if (
52
- pending_workflow.queue_name
53
- and pending_workflow.queue_name != "_dbos_internal_queue"
54
- ):
55
- try:
56
- dbos._sys_db.clear_queue_assignment(pending_workflow.workflow_uuid)
57
- workflow_handles.append(
58
- dbos.retrieve_workflow(pending_workflow.workflow_uuid)
59
- )
60
- except Exception as e:
61
- dbos.logger.error(e)
62
- else:
63
- workflow_handles.append(
64
- execute_workflow_by_id(dbos, pending_workflow.workflow_uuid)
57
+ try:
58
+ handle = _recover_workflow(dbos, pending_workflow)
59
+ workflow_handles.append(handle)
60
+ except Exception as e:
61
+ dbos.logger.error(
62
+ f"Exception encountered when recovering workflows: {traceback.format_exc()}"
65
63
  )
64
+ raise e
66
65
  dbos.logger.info(
67
- f"Recovering {len(pending_workflows)} workflows from version {dbos.app_version}"
66
+ f"Recovering {len(pending_workflows)} workflows for executor {executor_id} from version {GlobalParams.app_version}"
68
67
  )
69
68
  return workflow_handles
@@ -154,7 +154,7 @@ class SystemSchema:
154
154
  nullable=False,
155
155
  primary_key=True,
156
156
  ),
157
- Column("executor_id", Text),
157
+ # Column("executor_id", Text), # This column is deprecated. Do *not* use it.
158
158
  Column("queue_name", Text, nullable=False),
159
159
  Column(
160
160
  "created_at_epoch_ms",