Skip to content

Commit 857890c

Browse files
qianl15kraftp
andauthored
Fix Migration (#116) (#118)
Co-authored-by: Peter Kraft <[email protected]>
1 parent dee7bb4 commit 857890c

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""fix_job_queue
2+
3+
Revision ID: 50f3227f0b4b
4+
Revises: eab0cc1d9a14
5+
Create Date: 2024-09-25 14:03:53.308068
6+
7+
"""
8+
9+
from typing import Sequence, Union
10+
11+
from alembic import op
12+
13+
# revision identifiers, used by Alembic.
14+
revision: str = "50f3227f0b4b"
15+
down_revision: Union[str, None] = "eab0cc1d9a14"
16+
branch_labels: Union[str, Sequence[str], None] = None
17+
depends_on: Union[str, Sequence[str], None] = None
18+
19+
20+
def upgrade() -> None:
21+
op.drop_constraint("job_queue_pkey", "job_queue", schema="dbos", type_="primary")
22+
23+
op.create_primary_key(
24+
"job_queue_pkey", "job_queue", ["workflow_uuid"], schema="dbos"
25+
)
26+
27+
28+
def downgrade() -> None:
29+
# Reverting the changes
30+
op.drop_constraint("job_queue_pkey", "job_queue", schema="dbos", type_="primary")
31+
32+
op.create_primary_key(
33+
"job_queue_pkey", "job_queue", ["created_at_epoch_ms"], schema="dbos"
34+
)

dbos/queue.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import threading
22
import time
3+
import traceback
34
from typing import TYPE_CHECKING, Optional
45

56
from dbos.core import P, R, _execute_workflow_id, _start_workflow
6-
from dbos.error import DBOSInitializationError
77

88
if TYPE_CHECKING:
99
from dbos.dbos import DBOS, Workflow, WorkflowHandle
@@ -31,6 +31,13 @@ def queue_thread(stop_event: threading.Event, dbos: "DBOS") -> None:
3131
while not stop_event.is_set():
3232
time.sleep(1)
3333
for queue_name, queue in dbos._registry.queue_info_map.items():
34-
wf_ids = dbos._sys_db.start_queued_workflows(queue_name, queue.concurrency)
35-
for id in wf_ids:
36-
_execute_workflow_id(dbos, id)
34+
try:
35+
wf_ids = dbos._sys_db.start_queued_workflows(
36+
queue_name, queue.concurrency
37+
)
38+
for id in wf_ids:
39+
_execute_workflow_id(dbos, id)
40+
except Exception:
41+
dbos.logger.warning(
42+
f"Exception encountered in queue thread: {traceback.format_exc()}"
43+
)

0 commit comments

Comments
 (0)