File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,12 @@ async def drain_poll_queue(self) -> None:
195
195
except temporalio .bridge .worker .PollShutdownError :
196
196
return
197
197
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
+ await asyncio .gather (* running_tasks , return_exceptions = False )
203
+
198
204
def _cancel (
199
205
self , task_token : bytes , cancel : temporalio .bridge .proto .activity_task .Cancel
200
206
) -> None :
Original file line number Diff line number Diff line change @@ -467,6 +467,13 @@ async def raise_on_shutdown():
467
467
for task in tasks :
468
468
task .cancel ()
469
469
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
+
470
477
# Do final shutdown
471
478
try :
472
479
await self ._bridge_worker .finalize_shutdown ()
You can’t perform that action at this time.
0 commit comments