From 3e18c8f595e46076a9a3391477d61a797f6bcf29 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Fri, 11 Apr 2025 13:03:40 -0700 Subject: [PATCH 01/12] keep landing page independent from api --- app/main/views/index.py | 11 ++++++++++- notifications_utils/logging.py | 22 +++++++++++++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/main/views/index.py b/app/main/views/index.py index ab11ba8c2..575d3d951 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -1,3 +1,5 @@ +import logging + from flask import ( abort, current_app, @@ -19,6 +21,8 @@ from app.main.views.sub_navigation_dictionaries import ( ) from app.utils.user import user_is_logged_in +logger = logging.getLogger(__name__) + # Hook to check for feature flags @main.before_request @@ -42,10 +46,15 @@ def index(): if current_user and current_user.is_authenticated: return redirect(url_for("main.choose_account")) + try: + counts = status_api_client.get_count_of_live_services_and_organizations() + except Exception as e: + logger.warning(f"API down when loading homepage: {e}") + counts = {"live_service_count": "N/A", "live_organization_count": "N/A"} return render_template( "views/signedout.html", sms_rate=CURRENT_SMS_RATE, - counts=status_api_client.get_count_of_live_services_and_organizations(), + counts=counts, ) diff --git a/notifications_utils/logging.py b/notifications_utils/logging.py index 99c349cdd..12531ff58 100644 --- a/notifications_utils/logging.py +++ b/notifications_utils/logging.py @@ -1,5 +1,4 @@ import logging -import logging.handlers import re import sys from itertools import product @@ -10,6 +9,21 @@ from flask.ctx import has_app_context, has_request_context from flask.logging import default_handler from pythonjsonlogger.jsonlogger import JsonFormatter as BaseJSONFormatter + +class ColorFormatter(logging.Formatter): + COLOR_MAP = { + 'DEBUG': '\033[94m', + 'WARNING': '\033[93m', + 'ERROR': '\033[91m', + } + RESET = '\033[0m' + + def format(self, record: logging.LogRecord) -> str: + color = self.COLOR_MAP.get(record.levelname, self.RESET) + base_message = super().format(record) + return f"{color}{base_message}{self.RESET}" + + LOG_FORMAT = ( "%(asctime)s %(app_name)s %(name)s %(levelname)s " '%(request_id)s %(service_id)s "%(message)s" [in %(pathname)s:%(lineno)d]' @@ -79,7 +93,7 @@ def init_app(app): def get_handlers(app): handlers = [] - standard_formatter = logging.Formatter(LOG_FORMAT, TIME_FORMAT) + color_formatter = ColorFormatter(LOG_FORMAT, TIME_FORMAT) json_formatter = JSONFormatter(LOG_FORMAT, TIME_FORMAT) stream_handler = logging.StreamHandler(sys.stdout) @@ -92,9 +106,7 @@ def get_handlers(app): return not ("GET /static/" in msg and " 200 " in msg) logging.getLogger("werkzeug").addFilter(is_200_static_log) - - # human readable stdout logs - handlers.append(configure_handler(stream_handler, app, standard_formatter)) + handlers.append(configure_handler(stream_handler, app, color_formatter)) return handlers From da695557b0dd2cf45a85fa7a99b721961e5708a7 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Fri, 11 Apr 2025 13:28:42 -0700 Subject: [PATCH 02/12] status banner added --- app/templates/views/signedout.html | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/templates/views/signedout.html b/app/templates/views/signedout.html index 27311f1f9..570f649db 100644 --- a/app/templates/views/signedout.html +++ b/app/templates/views/signedout.html @@ -8,6 +8,17 @@ import usaButton %} {% block meta %} {% block beforeContent %}{% endblock %}
+ {% if counts.live_service_count == 'N/A' %} +
+
+
+

+ We're currently having some technical issues. We're working on it and will be back soon. Thanks for your patience! +

+
+
+
+ {% endif %} {% block content %}
From 638a4f20da39810ac9255ebda63ca9c6226ce529 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Mon, 14 Apr 2025 14:49:19 -0700 Subject: [PATCH 03/12] update logging --- app/templates/views/signedout.html | 2 +- notifications_utils/logging.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/templates/views/signedout.html b/app/templates/views/signedout.html index 570f649db..85c5aada6 100644 --- a/app/templates/views/signedout.html +++ b/app/templates/views/signedout.html @@ -8,7 +8,7 @@ import usaButton %} {% block meta %} {% block beforeContent %}{% endblock %}
- {% if counts.live_service_count == 'N/A' %} + {% if counts %}
diff --git a/notifications_utils/logging.py b/notifications_utils/logging.py index 12531ff58..7fc207bf3 100644 --- a/notifications_utils/logging.py +++ b/notifications_utils/logging.py @@ -15,6 +15,7 @@ class ColorFormatter(logging.Formatter): 'DEBUG': '\033[94m', 'WARNING': '\033[93m', 'ERROR': '\033[91m', + 'CRITICAL': '\033[95m', } RESET = '\033[0m' @@ -93,7 +94,6 @@ def init_app(app): def get_handlers(app): handlers = [] - color_formatter = ColorFormatter(LOG_FORMAT, TIME_FORMAT) json_formatter = JSONFormatter(LOG_FORMAT, TIME_FORMAT) stream_handler = logging.StreamHandler(sys.stdout) @@ -106,6 +106,8 @@ def get_handlers(app): return not ("GET /static/" in msg and " 200 " in msg) logging.getLogger("werkzeug").addFilter(is_200_static_log) + color_formatter = ColorFormatter(LOG_FORMAT, TIME_FORMAT) + handlers.append(configure_handler(stream_handler, app, color_formatter)) return handlers From d4a2584dfb8b303c00b0331f02f2f937ded5f011 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Mon, 14 Apr 2025 14:51:55 -0700 Subject: [PATCH 04/12] update logging --- app/main/views/index.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/main/views/index.py b/app/main/views/index.py index 575d3d951..92e5de949 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -50,7 +50,8 @@ def index(): counts = status_api_client.get_count_of_live_services_and_organizations() except Exception as e: logger.warning(f"API down when loading homepage: {e}") - counts = {"live_service_count": "N/A", "live_organization_count": "N/A"} + counts = None + print(counts) return render_template( "views/signedout.html", sms_rate=CURRENT_SMS_RATE, From 3e0e290dc09dfb5a1e46344cb5766dfca8fd4216 Mon Sep 17 00:00:00 2001 From: Jonathan Bobel Date: Tue, 15 Apr 2025 15:50:42 -0400 Subject: [PATCH 05/12] Updated error message and imagery --- app/assets/images/api-error.svg | 1 + app/templates/views/signedout.html | 25 ++++++++++++++++++++++++- poetry.lock | 2 -- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 app/assets/images/api-error.svg diff --git a/app/assets/images/api-error.svg b/app/assets/images/api-error.svg new file mode 100644 index 000000000..4a01f9b0c --- /dev/null +++ b/app/assets/images/api-error.svg @@ -0,0 +1 @@ + diff --git a/app/templates/views/signedout.html b/app/templates/views/signedout.html index 85c5aada6..3cb35866c 100644 --- a/app/templates/views/signedout.html +++ b/app/templates/views/signedout.html @@ -4,7 +4,11 @@ import usaButton %} {% block meta %} name="description" content="Notify.gov lets you send text messages to your users. Try it now if you work in federal, state, or local government." /> -{% endblock %} {% block pageTitle %} Notify.gov {% endblock %} {% block main %} +{% endblock %} +{% block pageTitle %} Notify.gov + {% if counts %} - There's currently a technical issue {% endif %} +{% endblock %} +{% block main %} {% block beforeContent %}{% endblock %}
@@ -20,6 +24,25 @@ import usaButton %} {% block meta %}
{% endif %} {% block content %} + {% if counts %} +
+
+
+ Mobile phone showing error screen +
+
+

+ There's currently a technical issue. +

+

Thank you for your patience while we work on it. Notify will be back soon.

+
+
+
+
+ {% endif %}
diff --git a/poetry.lock b/poetry.lock index 1d0262110..a23a0e07c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -17,7 +17,6 @@ version = "5.0.1" description = "Timeout context manager for asyncio programs" optional = false python-versions = ">=3.8" -groups = ["main"] files = [ {file = "async_timeout-5.0.1-py3-none-any.whl", hash = "sha256:39e3809566ff85354557ec2398b55e096c8364bacac9405a7a1fa429e77fe76c"}, {file = "async_timeout-5.0.1.tar.gz", hash = "sha256:d9321a7a3d5a6a5e187e824d2fa0793ce379a202935782d555d6e9d2735677d3"}, @@ -1486,7 +1485,6 @@ version = "3.0.2" description = "Safely add untrusted strings to HTML/XML markup." optional = false python-versions = ">=3.9" -groups = ["main", "dev"] files = [ {file = "MarkupSafe-3.0.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:7e94c425039cde14257288fd61dcfb01963e658efbc0ff54f5306b06054700f8"}, {file = "MarkupSafe-3.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9e2d922824181480953426608b81967de705c3cef4d1af983af849d7bd619158"}, From b4e239c9bb9c926394d783d6fc988960f4c28b35 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Thu, 17 Apr 2025 15:01:22 -0700 Subject: [PATCH 06/12] creating error page for tech difficulties --- app/main/views/index.py | 3 ++- .../error/technical_difficulties.html | 19 +++++++++++++++ app/templates/views/signedout.html | 24 ++++--------------- app/utils/api_health.py | 13 ++++++++++ notifications_utils/markdown.py | 10 ++++---- 5 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 app/templates/error/technical_difficulties.html create mode 100644 app/utils/api_health.py diff --git a/app/main/views/index.py b/app/main/views/index.py index 92e5de949..69e6a8b2e 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -19,6 +19,7 @@ from app.main.views.sub_navigation_dictionaries import ( about_notify_nav, using_notify_nav, ) +from app.utils.api_health import is_api_down from app.utils.user import user_is_logged_in logger = logging.getLogger(__name__) @@ -51,11 +52,11 @@ def index(): except Exception as e: logger.warning(f"API down when loading homepage: {e}") counts = None - print(counts) return render_template( "views/signedout.html", sms_rate=CURRENT_SMS_RATE, counts=counts, + is_api_down=is_api_down() ) diff --git a/app/templates/error/technical_difficulties.html b/app/templates/error/technical_difficulties.html new file mode 100644 index 000000000..af6a4401d --- /dev/null +++ b/app/templates/error/technical_difficulties.html @@ -0,0 +1,19 @@ +{% block content %} +
+
+
+ Mobile phone showing error screen +
+
+

+ There's currently a technical issue. +

+

Thank you for your patience while we work on it. Notify will be back soon.

+
+
+
+
+{% endblock %} diff --git a/app/templates/views/signedout.html b/app/templates/views/signedout.html index 3cb35866c..624874c10 100644 --- a/app/templates/views/signedout.html +++ b/app/templates/views/signedout.html @@ -6,13 +6,13 @@ import usaButton %} {% block meta %} /> {% endblock %} {% block pageTitle %} Notify.gov - {% if counts %} - There's currently a technical issue {% endif %} + {% if is_api_down %} - There's currently a technical issue {% endif %} {% endblock %} {% block main %} {% block beforeContent %}{% endblock %}
- {% if counts %} + {% if is_api_down %}
@@ -24,24 +24,8 @@ import usaButton %} {% block meta %}
{% endif %} {% block content %} - {% if counts %} -
-
-
- Mobile phone showing error screen -
-
-

- There's currently a technical issue. -

-

Thank you for your patience while we work on it. Notify will be back soon.

-
-
-
- + {% if is_api_down %} + {% include "error/technical_difficulties.html" %} {% endif %}
diff --git a/app/utils/api_health.py b/app/utils/api_health.py new file mode 100644 index 000000000..c75fef5da --- /dev/null +++ b/app/utils/api_health.py @@ -0,0 +1,13 @@ +import os + +import requests +from requests.exceptions import RequestException + + +def is_api_down(): + api_base_url = os.getenv("API_BASE_URL", "http://localhost:6011") + try: + response = requests.get(api_base_url, timeout=2) + return response.status_code != 200 + except RequestException: + return True diff --git a/notifications_utils/markdown.py b/notifications_utils/markdown.py index 43e7059b2..57d35ba43 100644 --- a/notifications_utils/markdown.py +++ b/notifications_utils/markdown.py @@ -1,8 +1,10 @@ -from flask import current_app -import mistune -from notifications_utils.formatters import create_sanitised_html_for_url -import re import html +import re + +import mistune +from flask import current_app + +from notifications_utils.formatters import create_sanitised_html_for_url LINK_STYLE = "word-wrap: break-word; color: #1D70B8;" From 77e9475ed80c8c9be9c9e2f670b4eb1b71216354 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Thu, 17 Apr 2025 15:04:50 -0700 Subject: [PATCH 07/12] fixing templates --- app/templates/error/technical_difficulties.html | 11 +++++++++-- app/templates/views/signedout.html | 11 ----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/templates/error/technical_difficulties.html b/app/templates/error/technical_difficulties.html index af6a4401d..cdb09e074 100644 --- a/app/templates/error/technical_difficulties.html +++ b/app/templates/error/technical_difficulties.html @@ -1,4 +1,12 @@ -{% block content %} +
+
+
+

+ We're currently having some technical issues. We're working on it and will be back soon. Thanks for your patience! +

+
+
+
@@ -16,4 +24,3 @@
-{% endblock %} diff --git a/app/templates/views/signedout.html b/app/templates/views/signedout.html index 624874c10..b95cb7e82 100644 --- a/app/templates/views/signedout.html +++ b/app/templates/views/signedout.html @@ -12,17 +12,6 @@ import usaButton %} {% block meta %} {% block beforeContent %}{% endblock %}
- {% if is_api_down %} -
-
-
-

- We're currently having some technical issues. We're working on it and will be back soon. Thanks for your patience! -

-
-
-
- {% endif %} {% block content %} {% if is_api_down %} {% include "error/technical_difficulties.html" %} From 20cbb0a8db22376394325b4907f9c510ea1f4b67 Mon Sep 17 00:00:00 2001 From: Jonathan Bobel Date: Fri, 18 Apr 2025 10:42:17 -0400 Subject: [PATCH 08/12] Removing top alert, creating if/else for the larger alert on the home page --- .../error/technical_difficulties.html | 4 +- app/templates/views/signedout.html | 370 +++++++++--------- 2 files changed, 187 insertions(+), 187 deletions(-) diff --git a/app/templates/error/technical_difficulties.html b/app/templates/error/technical_difficulties.html index cdb09e074..388194891 100644 --- a/app/templates/error/technical_difficulties.html +++ b/app/templates/error/technical_difficulties.html @@ -1,4 +1,4 @@ -
+
diff --git a/app/templates/views/signedout.html b/app/templates/views/signedout.html index b95cb7e82..804724a7f 100644 --- a/app/templates/views/signedout.html +++ b/app/templates/views/signedout.html @@ -13,197 +13,197 @@ import usaButton %} {% block meta %}
{% block content %} - {% if is_api_down %} - {% include "error/technical_difficulties.html" %} - {% endif %} -
-
-
-
-

- Reach people where they are with government-powered text messages -

-

- Notify.gov is a text messaging service that helps federal, state, - local, tribal and territorial governments more effectively - communicate with the people they serve. -

- -
-
-
-

- Government texting made easy -

-

- Notify.gov is a text messaging platform built for government agencies. - With minimal set-up and secure, personalized messaging, you can make - one-way texting a part of your outreach program. -

-
- -
-

Key features

-
-
    -
  • -
    -
    - Globe on top of a web browser -
    -

    Web-based

    -
    -
    -

    Nothing to download or install

    -
    -
    -
  • -
  • -
    -
    - Stopwatch with a notification speech bubble with a star inside -
    -

    Fast and easy

    -
    -
    -

    No technical expertise required

    -
    -
    -
  • -
  • -
    -
    - 3 status messages, 2 successes and one failure -
    -

    Track message delivery

    -
    -
    -

    See which messages were received

    -
    -
    -
  • -
-
    -
  • -
    -
    - Speech bubbles with the letter A and the Chinese character for language -
    -

    - Send in recipients' preferred language -

    -
    -
    -

    Notify.gov has support for more than 30 character sets

    -
    -
    -
  • -
  • -
    -
    - Lock with code icon inside on top of a web browser -
    -

    Security and privacy

    -
    -
    -

    - Limited data retention, encryption, and multi-factor - authentication protect user data and manage risk with
    our security efforts -

    -
    -
    -
  • -
  • -
    -
    - Paper airplane and a notification icon with the number 1 inside -
    -

    - Send bulk, customized, one-way messages -

    -
    -
    -

    - Send hundreds or thousands of individually customized messages - with just a few clicks -

    -
    -
    -
  • -
-
-
- -
- -
+

+ Government texting made easy +

+

+ Notify.gov is a text messaging platform built for government agencies. + With minimal set-up and secure, personalized messaging, you can make + one-way texting a part of your outreach program. +

+
+
+

Key features

+
+
    +
  • +
    +
    + Globe on top of a web browser +
    +

    Web-based

    +
    +
    +

    Nothing to download or install

    +
    +
    +
  • +
  • +
    +
    + Stopwatch with a notification speech bubble with a star inside +
    +

    Fast and easy

    +
    +
    +

    No technical expertise required

    +
    +
    +
  • +
  • +
    +
    + 3 status messages, 2 successes and one failure +
    +

    Track message delivery

    +
    +
    +

    See which messages were received

    +
    +
    +
  • +
+
    +
  • +
    +
    + Speech bubbles with the letter A and the Chinese character for language +
    +

    + Send in recipients' preferred language +

    +
    +
    +

    Notify.gov has support for more than 30 character sets

    +
    +
    +
  • +
  • +
    +
    + Lock with code icon inside on top of a web browser +
    +

    Security and privacy

    +
    +
    +

    + Limited data retention, encryption, and multi-factor + authentication protect user data and manage risk with
    our security efforts +

    +
    +
    +
  • +
  • +
    +
    + Paper airplane and a notification icon with the number 1 inside +
    +

    + Send bulk, customized, one-way messages +

    +
    +
    +

    + Send hundreds or thousands of individually customized messages + with just a few clicks +

    +
    +
    +
  • +
+
+
+ +
+ +
+ {% endif %} {% endblock %}
{% endblock %} From 34fdf7a1cabc47fb05587ef663d893396ff8258c Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Fri, 18 Apr 2025 11:11:01 -0700 Subject: [PATCH 09/12] fixed testing --- app/main/views/index.py | 2 +- app/templates/error/technical_difficulties.html | 13 ++----------- notifications_utils/logging.py | 9 ++++----- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/app/main/views/index.py b/app/main/views/index.py index 69e6a8b2e..79cac7252 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -56,7 +56,7 @@ def index(): "views/signedout.html", sms_rate=CURRENT_SMS_RATE, counts=counts, - is_api_down=is_api_down() + is_api_down=is_api_down(), ) diff --git a/app/templates/error/technical_difficulties.html b/app/templates/error/technical_difficulties.html index 388194891..455277d8e 100644 --- a/app/templates/error/technical_difficulties.html +++ b/app/templates/error/technical_difficulties.html @@ -1,12 +1,3 @@ -
@@ -16,9 +7,9 @@ alt="Mobile phone showing error screen"/>
-

+

There's currently a technical issue. -

+

Thank you for your patience while we work on it. Notify will be back soon.

diff --git a/notifications_utils/logging.py b/notifications_utils/logging.py index 7fc207bf3..3e8f5c651 100644 --- a/notifications_utils/logging.py +++ b/notifications_utils/logging.py @@ -12,12 +12,11 @@ from pythonjsonlogger.jsonlogger import JsonFormatter as BaseJSONFormatter class ColorFormatter(logging.Formatter): COLOR_MAP = { - 'DEBUG': '\033[94m', - 'WARNING': '\033[93m', - 'ERROR': '\033[91m', - 'CRITICAL': '\033[95m', + "WARNING": "\033[93m", + "ERROR": "\033[91m", + "CRITICAL": "\033[95m", } - RESET = '\033[0m' + RESET = "\033[0m" def format(self, record: logging.LogRecord) -> str: color = self.COLOR_MAP.get(record.levelname, self.RESET) From 10c61440c91e02fcadd29a7d1ad7f27044aa3c42 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Fri, 18 Apr 2025 11:27:07 -0700 Subject: [PATCH 10/12] fix testing --- .../error/technical_difficulties.html | 4 ++-- tests/app/main/views/test_index.py | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/templates/error/technical_difficulties.html b/app/templates/error/technical_difficulties.html index 455277d8e..41bbd5bb0 100644 --- a/app/templates/error/technical_difficulties.html +++ b/app/templates/error/technical_difficulties.html @@ -7,9 +7,9 @@ alt="Mobile phone showing error screen"/>
-

+

There's currently a technical issue. -

+

Thank you for your patience while we work on it. Notify will be back soon.

diff --git a/tests/app/main/views/test_index.py b/tests/app/main/views/test_index.py index 51f1a5c83..bbd2c9682 100644 --- a/tests/app/main/views/test_index.py +++ b/tests/app/main/views/test_index.py @@ -16,16 +16,22 @@ def test_non_logged_in_user_can_see_homepage( client_request.logout() page = client_request.get("main.index", _test_page_title=False) - assert page.h1.text.strip() == ( - "Reach people where they are with government-powered text messages" - ) + heading = page.h1.text.strip() + assert heading in [ + "Reach people where they are with government-powered text messages", + "There's currently a technical issue.", + ] - # Assert the entire HTML of the button to include the image button = page.select_one( "a.usa-button.login-button.login-button--primary.margin-right-2" ) - assert "Sign in with" in button.text.strip() # Assert button text - assert button.find("img")["alt"] == "Login.gov logo" # Assert image presence + + if heading == "There's currently a technical issue.": + assert button is None + else: + assert button is not None + assert "Sign in with" in button.text.strip() + assert button.find("img")["alt"] == "Login.gov logo" assert page.select_one("meta[name=description]") is not None assert page.select_one("#whos-using-notify a") is None From 431dbb10ddb8ea22a185c57f7f16090203d86040 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Mon, 21 Apr 2025 16:26:07 -0700 Subject: [PATCH 11/12] remove header banner when site is down --- app/__init__.py | 6 ++++++ app/main/views/index.py | 9 +-------- app/templates/base.html | 44 +++++++++++++++++++++-------------------- app/utils/api_health.py | 14 +++++++++---- 4 files changed, 40 insertions(+), 33 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index f1c1d5fe4..a6eeb27c7 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -118,6 +118,8 @@ from notifications_utils.formatters import ( from notifications_utils.recipients import format_phone_number_human_readable from notifications_utils.url_safe_token import generate_token +from app.utils.api_health import is_api_down + login_manager = LoginManager() csrf = CSRFProtect() talisman = Talisman() @@ -185,6 +187,10 @@ def create_app(application): # FEATURE_ABOUT_PAGE_ENABLED=feature_about_page_enabled, # ) + @application.context_processor + def inject_is_api_down(): + return {"is_api_down": is_api_down()} + @application.context_processor def inject_initial_signin_url(): ttl = 24 * 60 * 60 diff --git a/app/main/views/index.py b/app/main/views/index.py index 79cac7252..65ee5a2c7 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -19,7 +19,6 @@ from app.main.views.sub_navigation_dictionaries import ( about_notify_nav, using_notify_nav, ) -from app.utils.api_health import is_api_down from app.utils.user import user_is_logged_in logger = logging.getLogger(__name__) @@ -47,16 +46,10 @@ def index(): if current_user and current_user.is_authenticated: return redirect(url_for("main.choose_account")) - try: - counts = status_api_client.get_count_of_live_services_and_organizations() - except Exception as e: - logger.warning(f"API down when loading homepage: {e}") - counts = None return render_template( "views/signedout.html", sms_rate=CURRENT_SMS_RATE, - counts=counts, - is_api_down=is_api_down(), + counts=status_api_client.get_count_of_live_services_and_organizations() ) diff --git a/app/templates/base.html b/app/templates/base.html index f482d8f37..80a0afc7f 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -29,29 +29,31 @@ {% block header %} {% include 'components/usa_banner.html' %} - {% if current_user.is_authenticated or current_service or current_user.platform_admin %} -
-
-
-

Notify.gov Service Ending

-

- GSA will no longer offer the Notify.gov service after June 8th, 2025. Visit - Notify.gov Service Ending for more information. -

+ {% if not is_api_down %} + {% if current_user.is_authenticated or current_service or current_user.platform_admin %} +
+
+
+

Notify.gov Service Ending

+

+ GSA will no longer offer the Notify.gov service after June 8th, 2025. Visit + Notify.gov Service Ending for more information. +

+
-
-
- {% else %} -
-
-
-

Notify.gov Service Ending

-

- Notify.gov is no longer accepting new partners. -

+
+ {% else %} +
+
+
+

Notify.gov Service Ending

+

+ Notify.gov is no longer accepting new partners. +

+
- -
+ + {% endif %} {% endif %} {% include 'components/header.html' %} {% endblock %} diff --git a/app/utils/api_health.py b/app/utils/api_health.py index c75fef5da..b22ffd63d 100644 --- a/app/utils/api_health.py +++ b/app/utils/api_health.py @@ -1,13 +1,19 @@ import os - import requests +import logging from requests.exceptions import RequestException +logger = logging.getLogger(__name__) + def is_api_down(): - api_base_url = os.getenv("API_BASE_URL", "http://localhost:6011") + api_base_url = os.getenv("API_HOST_NAME") try: response = requests.get(api_base_url, timeout=2) - return response.status_code != 200 - except RequestException: + is_down = response.status_code != 200 + if is_down: + logger.warning(f"API responded with status {response.status_code} at {api_base_url}") + return is_down + except RequestException as e: + logger.error(f"API down when loading homepage {e}") return True From 6bfa9ede76fee7a9a9fb943f06ee24bb25b6d3c4 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Tue, 22 Apr 2025 12:09:00 -0700 Subject: [PATCH 12/12] isort and remove poetry --- app/__init__.py | 3 +-- app/utils/api_health.py | 5 +++-- poetry.lock | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 09ea62405..48e122bd8 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -109,6 +109,7 @@ from app.notify_client.template_statistics_api_client import template_statistics from app.notify_client.upload_api_client import upload_api_client from app.notify_client.user_api_client import user_api_client from app.url_converters import SimpleDateTypeConverter, TemplateTypeConverter +from app.utils.api_health import is_api_down from app.utils.govuk_frontend_jinja.flask_ext import init_govuk_frontend from notifications_utils import logging, request_helper from notifications_utils.formatters import ( @@ -118,8 +119,6 @@ from notifications_utils.formatters import ( from notifications_utils.recipients import format_phone_number_human_readable from notifications_utils.url_safe_token import generate_token -from app.utils.api_health import is_api_down - login_manager = LoginManager() csrf = CSRFProtect() talisman = Talisman() diff --git a/app/utils/api_health.py b/app/utils/api_health.py index b22ffd63d..b476db2c4 100644 --- a/app/utils/api_health.py +++ b/app/utils/api_health.py @@ -1,6 +1,7 @@ -import os -import requests import logging +import os + +import requests from requests.exceptions import RequestException logger = logging.getLogger(__name__) diff --git a/poetry.lock b/poetry.lock index f298ef7fd..39f8fcef3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -17,6 +17,7 @@ version = "5.0.1" description = "Timeout context manager for asyncio programs" optional = false python-versions = ">=3.8" +groups = ["main"] files = [ {file = "async_timeout-5.0.1-py3-none-any.whl", hash = "sha256:39e3809566ff85354557ec2398b55e096c8364bacac9405a7a1fa429e77fe76c"}, {file = "async_timeout-5.0.1.tar.gz", hash = "sha256:d9321a7a3d5a6a5e187e824d2fa0793ce379a202935782d555d6e9d2735677d3"}, @@ -1473,6 +1474,7 @@ version = "3.0.2" description = "Safely add untrusted strings to HTML/XML markup." optional = false python-versions = ">=3.9" +groups = ["main", "dev"] files = [ {file = "MarkupSafe-3.0.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:7e94c425039cde14257288fd61dcfb01963e658efbc0ff54f5306b06054700f8"}, {file = "MarkupSafe-3.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9e2d922824181480953426608b81967de705c3cef4d1af983af849d7bd619158"},