Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added total running time to gunicorn shutdown hooks #2365

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion gunicorn_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import time
import traceback

import gunicorn # type: ignore
Expand All @@ -15,7 +16,12 @@
# Guincorn sets the server type on our app. We don't want to show it in the header in the response.
gunicorn.SERVER = "Undisclosed"

on_aws = os.environ.get("NOTIFY_ENVIRONMENT", "") in ["production", "staging", "scratch", "dev"]
on_aws = os.environ.get("NOTIFY_ENVIRONMENT", "") in [
"production",
"staging",
"scratch",
"dev",
]
if on_aws:
# To avoid load balancers reporting errors on shutdown instances, see AWS doc
# > We also recommend that you configure the idle timeout of your application
Expand Down Expand Up @@ -46,6 +52,9 @@
graceful_timeout = 85
timeout = 90

# Start timer for total running time
start_time = time.time()


def on_starting(server):
server.log.info("Starting Notifications API")
Expand All @@ -58,7 +67,9 @@ def worker_abort(worker):


def on_exit(server):
elapsed_time = time.time() - start_time
server.log.info("Stopping Notifications API")
server.log.info("Total gunicorn running time: {:.2f} seconds".format(elapsed_time))


def worker_int(worker):
Expand Down
Loading