Skip to content

Commit

Permalink
Merge branch 'develop' into py313
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanBalfanz authored Oct 24, 2024
2 parents 99bedae + 4ee3050 commit 7f911d4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions baseplate/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,20 +349,28 @@ def load_app_and_run_server() -> None:
server.start()
try:
shutdown_event.wait()
logger.info("Shutdown triggered.")

SERVER_STATE.state = ServerLifecycle.SHUTTING_DOWN

cfg = parse_config(config.server, {"drain_time": OptionalConfig(Timespan)})
# Default drain time across all baseplate language implementations
# which allows enough time for systems such as k8s to remove the
# server from the endpoints list.
#
# During drain time, the server still accepts connections as normal. This is
# to allow clients time to notice the server is going away and stop sending
# requests to it.
drain_time_seconds = 5
if cfg.drain_time:
drain_time_seconds = cfg.drain_time.total_seconds()
logger.debug("Draining inbound requests...")
logger.info("Draining inbound requests...")
time.sleep(drain_time_seconds)
finally:
logger.debug("Gracefully shutting down...")
logger.info("Gracefully shutting down...")

# Stop accepting new connections immediately, and wait for existing ones to finish.
# This hangs until all connections are closed or until stop_timeout is reached.
server.stop()
logger.info("Exiting")

Expand Down

0 comments on commit 7f911d4

Please sign in to comment.