File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,13 @@ async def drain_poll_queue(self) -> None:
195195 except temporalio .bridge .worker .PollShutdownError :
196196 return
197197
198+ # Only call this after run()/drain_poll_queue() have returned. This will not
199+ # raise an exception.
200+ async def wait_all_completed (self ) -> None :
201+ running_tasks = [v .task for v in self ._running_activities .values () if v .task ]
202+ if running_tasks :
203+ await asyncio .gather (* running_tasks , return_exceptions = False )
204+
198205 def _cancel (
199206 self , task_token : bytes , cancel : temporalio .bridge .proto .activity_task .Cancel
200207 ) -> None :
Original file line number Diff line number Diff line change @@ -467,6 +467,13 @@ async def raise_on_shutdown():
467467 for task in tasks :
468468 task .cancel ()
469469
470+ # If there's an activity worker, we have to let all activity completions
471+ # finish. We cannot guarantee that because poll shutdown completed
472+ # (which means activities completed) that they got flushed to the
473+ # server.
474+ if self ._activity_worker :
475+ await self ._activity_worker .wait_all_completed ()
476+
470477 # Do final shutdown
471478 try :
472479 await self ._bridge_worker .finalize_shutdown ()
You can’t perform that action at this time.
0 commit comments