Change function and variable names for readability and consistency

This commit is contained in:
Pea Tyczynska
2020-06-01 11:45:35 +01:00
parent a4b942cf6c
commit c96142ba5e
8 changed files with 57 additions and 53 deletions

View File

@@ -89,19 +89,19 @@ def dao_create_notification(notification):
db.session.add(notification)
def _decide_permanent_temporary_failure(status, notification, code=None):
def _decide_permanent_temporary_failure(status, notification, detailed_status_code=None):
# If we get failure status from Firetext, we want to know if this is temporary or permanent failure.
# So we check the failure code to learn that.
# If there is no failure code, or we do not recognise the failure code, we do the following:
# if notifitcation goes form status pending to status failure, we mark it as temporary failure;
# if notification goes straight to status failure, we mark it as permanent failure.
if status == NOTIFICATION_PERMANENT_FAILURE and code not in [None, '000']:
if status == NOTIFICATION_PERMANENT_FAILURE and detailed_status_code not in [None, '000']:
try:
status, reason = get_message_status_and_reason_from_firetext_code(code)
status, reason = get_message_status_and_reason_from_firetext_code(detailed_status_code)
current_app.logger.info(f'Updating notification id {notification.id} to status {status}, reason: {reason}')
return status
except KeyError:
current_app.logger.warning(f'Failure code {code} from Firetext not recognised')
current_app.logger.warning(f'Failure code {detailed_status_code} from Firetext not recognised')
# fallback option:
if notification.status == NOTIFICATION_PENDING and status == NOTIFICATION_PERMANENT_FAILURE:
status = NOTIFICATION_TEMPORARY_FAILURE
@@ -113,8 +113,10 @@ def country_records_delivery(phone_prefix):
return dlr and dlr.lower() == 'yes'
def _update_notification_status(notification, status, code=None):
status = _decide_permanent_temporary_failure(status=status, notification=notification, code=code)
def _update_notification_status(notification, status, detailed_status_code=None):
status = _decide_permanent_temporary_failure(
status=status, notification=notification, detailed_status_code=detailed_status_code
)
notification.status = status
dao_update_notification(notification)
return notification
@@ -122,7 +124,7 @@ def _update_notification_status(notification, status, code=None):
@statsd(namespace="dao")
@transactional
def update_notification_status_by_id(notification_id, status, sent_by=None, code=None):
def update_notification_status_by_id(notification_id, status, sent_by=None, detailed_status_code=None):
notification = Notification.query.with_for_update().filter(Notification.id == notification_id).first()
if not notification:
@@ -149,7 +151,7 @@ def update_notification_status_by_id(notification_id, status, sent_by=None, code
return _update_notification_status(
notification=notification,
status=status,
code=code
detailed_status_code=detailed_status_code
)