Skip to content

Commit 2cba63a

Browse files
authored
Bump pydocket version and remove background worker shutdown timeout (#19969)
1 parent e1b5996 commit 2cba63a

File tree

3 files changed

+75
-94
lines changed

3 files changed

+75
-94
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ dependencies = [
8080
"whenever>=0.7.3,<0.10.0; python_version>='3.13'",
8181
"semver>=3.0.4",
8282
"pluggy>=1.6.0",
83-
"pydocket>=0.13.0",
83+
"pydocket>=0.16.2",
8484
]
8585
[project.urls]
8686
Changelog = "https://github.com/PrefectHQ/prefect/releases"

src/prefect/server/api/background_workers.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async def background_worker(
4747
webserver_only: bool = False,
4848
) -> AsyncGenerator[None, None]:
4949
worker_task: asyncio.Task[None] | None = None
50-
try:
50+
async with Worker(docket) as worker:
5151
# Register background task functions
5252
docket.register_collection(
5353
"prefect.server.api.background_workers:task_functions"
@@ -58,24 +58,14 @@ async def background_worker(
5858
docket, ephemeral=ephemeral, webserver_only=webserver_only
5959
)
6060

61-
async with Worker(docket) as worker:
61+
try:
6262
worker_task = asyncio.create_task(worker.run_forever())
6363
yield
6464

65-
finally:
66-
if worker_task:
67-
worker_task.cancel()
68-
try:
69-
logger.debug(
70-
"Waiting for background worker to finish after cancellation..."
71-
)
72-
await asyncio.wait_for(worker_task, timeout=5.0)
73-
logger.debug(
74-
"Background worker finished successfully after cancellation"
75-
)
76-
except asyncio.TimeoutError:
77-
logger.debug(
78-
"Background worker did not finish within 5 seconds after cancellation. Proceeding with shutdown"
79-
)
80-
except asyncio.CancelledError:
81-
pass
65+
finally:
66+
if worker_task:
67+
worker_task.cancel()
68+
try:
69+
await worker_task
70+
except asyncio.CancelledError:
71+
pass

0 commit comments

Comments
 (0)