mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Added tests for statsd and provider stats outcomes with the new provider stats tasks
- note large change to DAO to remove provider from create notification. Added on send now not creation.
This commit is contained in:
@@ -26,13 +26,12 @@ from notifications_utils.template import (
|
||||
unlink_govuk_escaped
|
||||
)
|
||||
|
||||
|
||||
retry_iteration_to_delay = {
|
||||
0: 5, # 5 seconds
|
||||
1: 30, # 30 seconds
|
||||
2: 60 * 5, # 5 minutes
|
||||
3: 60 * 15, # 15 minutes
|
||||
4: 60 * 30 # 30 minutes
|
||||
0: 5, # 5 seconds
|
||||
1: 30, # 30 seconds
|
||||
2: 60 * 5, # 5 minutes
|
||||
3: 60 * 15, # 15 minutes
|
||||
4: 60 * 30 # 30 minutes
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +69,11 @@ def send_sms_to_provider(self, service_id, notification_id, encrypted_notificati
|
||||
content_char_count=template.replaced_content_count
|
||||
)
|
||||
|
||||
notification.sent_at = datetime.utcnow()
|
||||
notification.sent_by = provider.get_name(),
|
||||
notification.content_char_count = template.replaced_content_count
|
||||
dao_update_notification(notification)
|
||||
|
||||
except SmsClientException as e:
|
||||
try:
|
||||
current_app.logger.error(
|
||||
@@ -79,14 +83,6 @@ def send_sms_to_provider(self, service_id, notification_id, encrypted_notificati
|
||||
raise self.retry(queue="retry", countdown=retry_iteration_to_delay[self.request.retries])
|
||||
except self.MaxRetriesExceededError:
|
||||
notification.status = 'technical-failure'
|
||||
except SQLAlchemyError as e:
|
||||
current_app.logger.exception(e)
|
||||
raise self.retry(queue="retry", exc=e)
|
||||
|
||||
notification.sent_at = datetime.utcnow()
|
||||
notification.sent_by = provider.get_name(),
|
||||
notification.content_char_count = template.replaced_content_count
|
||||
dao_update_notification(notification)
|
||||
|
||||
current_app.logger.info(
|
||||
"SMS {} created at {} sent at {}".format(notification_id, notification.created_at, notification.sent_at)
|
||||
|
||||
@@ -197,8 +197,9 @@ def _update_notification_stats_query(notification_type, status):
|
||||
|
||||
def _update_statistics(notification, notification_statistics_status):
|
||||
if notification.job_id:
|
||||
db.session.query(Job).filter_by(id=notification.job_id
|
||||
).update(_update_job_stats_query(notification_statistics_status))
|
||||
db.session.query(Job).filter_by(
|
||||
id=notification.job_id
|
||||
).update(_update_job_stats_query(notification_statistics_status))
|
||||
|
||||
db.session.query(NotificationStatistics).filter_by(
|
||||
day=notification.created_at.date(),
|
||||
@@ -231,17 +232,16 @@ def _update_notification_status(notification, status, notification_statistics_st
|
||||
if notification_statistics_status:
|
||||
_update_statistics(notification, notification_statistics_status)
|
||||
|
||||
db.session.query(Notification).filter(Notification.id == notification.id
|
||||
).update({Notification.status: status})
|
||||
db.session.query(Notification).filter(Notification.id == notification.id).update({Notification.status: status})
|
||||
return True
|
||||
|
||||
|
||||
@transactional
|
||||
def update_notification_status_by_id(notification_id, status, notification_statistics_status=None):
|
||||
notification = Notification.query.filter(Notification.id == notification_id,
|
||||
or_(Notification.status == 'sending',
|
||||
Notification.status == 'pending')
|
||||
).first()
|
||||
notification = Notification.query.filter(
|
||||
Notification.id == notification_id,
|
||||
or_(Notification.status == 'sending',
|
||||
Notification.status == 'pending')).first()
|
||||
|
||||
if not notification:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user