@@ -351,6 +351,7 @@ def create(
351351 engine : Optional [sa .Engine ],
352352 schema : Optional [str ],
353353 serializer : Serializer ,
354+ executor_id : Optional [str ],
354355 debug_mode : bool = False ,
355356 ) -> "SystemDatabase" :
356357 """Factory method to create the appropriate SystemDatabase implementation based on URL."""
@@ -363,6 +364,7 @@ def create(
363364 engine = engine ,
364365 schema = schema ,
365366 serializer = serializer ,
367+ executor_id = executor_id ,
366368 debug_mode = debug_mode ,
367369 )
368370 else :
@@ -374,6 +376,7 @@ def create(
374376 engine = engine ,
375377 schema = schema ,
376378 serializer = serializer ,
379+ executor_id = executor_id ,
377380 debug_mode = debug_mode ,
378381 )
379382
@@ -385,6 +388,7 @@ def __init__(
385388 engine : Optional [sa .Engine ],
386389 schema : Optional [str ],
387390 serializer : Serializer ,
391+ executor_id : Optional [str ],
388392 debug_mode : bool = False ,
389393 ):
390394 import sqlalchemy .dialects .postgresql as pg
@@ -410,6 +414,8 @@ def __init__(
410414
411415 self .notifications_map = ThreadSafeConditionDict ()
412416 self .workflow_events_map = ThreadSafeConditionDict ()
417+ self .executor_id = executor_id
418+
413419 self ._listener_thread_lock = threading .Lock ()
414420
415421 # Now we can run background processes
@@ -1069,6 +1075,27 @@ def _record_operation_result_txn(
10691075 error = result ["error" ]
10701076 output = result ["output" ]
10711077 assert error is None or output is None , "Only one of error or output can be set"
1078+ wf_executor_id_row = conn .execute (
1079+ sa .select (
1080+ SystemSchema .workflow_status .c .executor_id ,
1081+ ).where (
1082+ SystemSchema .workflow_status .c .workflow_uuid == result ["workflow_uuid" ]
1083+ )
1084+ ).fetchone ()
1085+ assert wf_executor_id_row is not None
1086+ wf_executor_id = wf_executor_id_row [0 ]
1087+ if self .executor_id is not None and wf_executor_id != self .executor_id :
1088+ dbos_logger .debug (
1089+ f'Resetting executor_id from { wf_executor_id } to { self .executor_id } for workflow { result ["workflow_uuid" ]} '
1090+ )
1091+ conn .execute (
1092+ sa .update (SystemSchema .workflow_status )
1093+ .values (executor_id = self .executor_id )
1094+ .where (
1095+ SystemSchema .workflow_status .c .workflow_uuid
1096+ == result ["workflow_uuid" ]
1097+ )
1098+ )
10721099 sql = sa .insert (SystemSchema .operation_outputs ).values (
10731100 workflow_uuid = result ["workflow_uuid" ],
10741101 function_id = result ["function_id" ],
0 commit comments