Skip to content

Commit

Permalink
#1895 Provider Service log level (#1961)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchlwellman authored Aug 28, 2024
1 parent 936028a commit c34a37e
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions app/provider_details/provider_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from flask import current_app

from app.dao.provider_details_dao import get_provider_details_by_id
from app.exceptions import InvalidProviderException
from app.models import Notification, ProviderDetails
Expand All @@ -9,10 +10,6 @@
)
from typing import Type, Dict, Optional

logging.basicConfig(format='%(levelname)s %(asctime)s %(pathname)s:%(lineno)d: %(message)s')
logger = logging.getLogger('notification-api.provider_switching')
logger.setLevel(logging.DEBUG)


class ProviderService:
def __init__(self):
Expand Down Expand Up @@ -56,15 +53,18 @@ def get_provider(

# This is a UUID (ProviderDetails primary key).
provider_id = self._get_template_or_service_provider_id(notification)
logger.debug('notification = %s', notification)
logger.debug('provider_id = %s', provider_id)
current_app.logger.debug(
'Provider service getting provider for notification = %s, provider_id = %s', notification.id, provider_id
)

if provider_id:
provider = get_provider_details_by_id(provider_id)
elif notification.notification_type != NotificationType.SMS:
# Use an alternative strategy to determine the provider.
provider_selection_strategy = self._strategies.get(NotificationType(notification.notification_type))
logger.debug('Provider selection strategy: %s', provider_selection_strategy)
current_app.logger.debug(
'Provider selection strategy: %s, for notification: %s', provider_selection_strategy, notification.id
)
provider = (
None
if (provider_selection_strategy is None)
Expand All @@ -89,7 +89,11 @@ def get_provider(
elif not provider.active:
raise InvalidProviderException(f'The provider {provider.display_name} is not active.')

logger.debug('Returning provider: %s', None if provider is None else provider.display_name)
current_app.logger.debug(
'Returning provider: %s, for notification %s',
None if provider is None else provider.display_name,
notification.id,
)
return provider

@staticmethod
Expand All @@ -106,18 +110,28 @@ def _get_template_or_service_provider_id(notification: Notification) -> Optional
# TODO #957 - The field is nullable, but what does SQLAlchemy return? An empty string?
# Testing for None broke a user flows test; user flows is since removed but this is possibly an issue?
if notification.template.provider_id:
logger.debug('Found template provider ID %s', notification.template.provider_id)
current_app.logger.debug(
'Found template provider ID %s, for notification %s', notification.template.provider_id, notification.id
)
return notification.template.provider_id

# A template provider_id is not available. Try using a service provider_id, which might also be None.
if notification.notification_type == NotificationType.EMAIL.value:
logger.debug('Service provider e-mail ID %s', notification.service.email_provider_id)
current_app.logger.debug(
'Service provider e-mail ID %s, for notification %s',
notification.service.email_provider_id,
notification.id,
)
return notification.service.email_provider_id
elif notification.notification_type == NotificationType.SMS.value:
logger.debug('Service provider SMS ID %s', notification.service.sms_provider_id)
current_app.logger.debug(
'Service provider SMS ID %s, for notification %s', notification.service.sms_provider_id, notification.id
)
return notification.service.sms_provider_id

# TODO #957 - What about letters? That is the 3rd enumerated value in NotificationType
# and Notification.notification_type.
logger.critical('Unanticipated notification type: %s', notification.notification_type)
current_app.logger.critical(
'Unanticipated notification type: %s for notification %s', notification.notification_type, notification.id
)
return None

0 comments on commit c34a37e

Please sign in to comment.