Skip to content

Commit 70e5e2b

Browse files
committed
Use env variable for graceful shutdown time period
Signed-off-by: Sreekanth <prsreekanth920@gmail.com>
1 parent dcbd0d5 commit 70e5e2b

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

packages/pynumaflow/pynumaflow/_constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
# If NUM_THREADS_DEFAULT env is not set default to 4
6262
NUM_THREADS_DEFAULT = int(os.getenv("MAX_THREADS", "4"))
6363

64+
# Grace period in seconds for the GRPC server to shutdown
65+
NUMAFLOW_GRPC_SHUTDOWN_GRACE_PERIOD_SECONDS = int(
66+
os.getenv("NUMAFLOW_GRPC_SHUTDOWN_GRACE_PERIOD_SECONDS", "60")
67+
)
68+
6469
_LOGGER = setup_logging(__name__)
6570
if os.getenv("PYTHONDEBUG"):
6671
_LOGGER.setLevel(logging.DEBUG)

packages/pynumaflow/pynumaflow/sinker/async_server.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
ON_SUCCESS_SINK_SOCK_PATH,
2727
ON_SUCCESS_SINK_SERVER_INFO_FILE_PATH,
2828
MAX_NUM_THREADS,
29+
NUMAFLOW_GRPC_SHUTDOWN_GRACE_PERIOD_SECONDS,
2930
)
3031

3132
from pynumaflow.shared.server import NumaflowServer
@@ -168,9 +169,9 @@ async def _watch_for_shutdown():
168169
"""Wait for the shutdown event and stop the server with a grace period."""
169170
await shutdown_event.wait()
170171
_LOGGER.info("Shutdown signal received, stopping server gracefully...")
171-
# Stop accepting new requests and wait for a maximum of 5 seconds
172-
# for in-flight requests to complete
173-
await server.stop(5)
172+
# Stop accepting new requests and wait for a maximum of
173+
# NUMAFLOW_GRPC_SHUTDOWN_GRACE_PERIOD_SECONDS seconds for in-flight requests to complete
174+
await server.stop(NUMAFLOW_GRPC_SHUTDOWN_GRACE_PERIOD_SECONDS)
174175

175176
shutdown_task = asyncio.create_task(_watch_for_shutdown())
176177
await server.wait_for_termination()

0 commit comments

Comments
 (0)