Skip to content

Commit

Permalink
Configurable timeout for client startup and shout down
Browse files Browse the repository at this point in the history
In some rear cases load on a computer can be so high that the startup
and shoutdown may use longer than the hard coded 30 seconds. This
change make these configurable to handle these cases.
  • Loading branch information
asmundo authored and Åsmund Østvold committed May 12, 2023
1 parent 93c41a0 commit c9d06e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/prefect/client/base.py
Expand Up @@ -18,6 +18,8 @@
from prefect.settings import (
PREFECT_CLIENT_RETRY_EXTRA_CODES,
PREFECT_CLIENT_RETRY_JITTER_FACTOR,
PREFECT_CLIENT_LIFESPAN_CONTEXT_STARTUP_TIMEOUT,
PREFECT_CLIENT_LIFESPAN_CONTEXT_SHOUTDOWN_TIMEOUT,
)
from prefect.utilities.math import bounded_poisson_interval, clamped_poisson_interval

Expand Down Expand Up @@ -88,7 +90,9 @@ async def app_lifespan_context(app: FastAPI) -> ContextManager[None]:
else:
# Create a new lifespan manager
APP_LIFESPANS[key] = context = LifespanManager(
app, startup_timeout=30, shutdown_timeout=30
app,
startup_timeout=PREFECT_CLIENT_LIFESPAN_CONTEXT_STARTUP_TIMEOUT.value(),
shutdown_timeout=PREFECT_CLIENT_LIFESPAN_CONTEXT_SHOUTDOWN_TIMEOUT.value(),
)
APP_LIFESPANS_REF_COUNTS[key] = 1

Expand Down
22 changes: 22 additions & 0 deletions src/prefect/settings.py
Expand Up @@ -1042,6 +1042,28 @@ def default_cloud_ui_url(settings, value):
API with another tool you will need to configure this there instead.
"""

PREFECT_CLIENT_LIFESPAN_CONTEXT_STARTUP_TIMEOUT = Setting(
int,
default=30,
)
"""
The time the client has to startup before we expect it has failed
without reporting back.
The client may in extreme load use an unknown starting up.
"""

PREFECT_CLIENT_LIFESPAN_CONTEXT_SHOUTDOWN_TIMEOUT = Setting(
int,
default=30,
)
"""
The time the client has to shouting down before we expect it has
failed without completed.
The client may in extreme load use an unknown shouting down.
"""

PREFECT_UI_ENABLED = Setting(
bool,
default=True,
Expand Down

0 comments on commit c9d06e3

Please sign in to comment.