mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Removed contented updates the notifications stats table
- As before this is now driven from the notifications history table - Removed from updates and create - Signatures changes to removed unused params hits many files - Also potential issue around rate limiting - we used to get the number sent per day from the stats table - which was a single row lookup, now we have to count this. This applies to EVERY API CALL. Probably not a good thing and should be addressed urgently.
This commit is contained in:
@@ -93,7 +93,7 @@ def send_sms_to_provider(self, service_id, notification_id):
|
||||
"RETRY FAILED: task send_sms_to_provider failed for notification {}".format(notification.id),
|
||||
e
|
||||
)
|
||||
update_notification_status_by_id(notification.id, 'technical-failure', 'failure')
|
||||
update_notification_status_by_id(notification.id, 'technical-failure')
|
||||
|
||||
current_app.logger.info(
|
||||
"SMS {} sent to provider at {}".format(notification_id, notification.sent_at)
|
||||
@@ -172,7 +172,7 @@ def send_email_to_provider(self, service_id, notification_id):
|
||||
"RETRY FAILED: task send_email_to_provider failed for notification {}".format(notification.id),
|
||||
e
|
||||
)
|
||||
update_notification_status_by_id(notification.id, 'technical-failure', 'failure')
|
||||
update_notification_status_by_id(notification.id, 'technical-failure')
|
||||
|
||||
current_app.logger.info(
|
||||
"Email {} sent to provider at {}".format(notification_id, notification.sent_at)
|
||||
|
||||
@@ -91,10 +91,10 @@ def timeout_notifications():
|
||||
seconds=current_app.config.get('SENDING_NOTIFICATIONS_TIMEOUT_PERIOD')
|
||||
):
|
||||
# TODO: think about making this a bulk update rather than one at a time.
|
||||
updated = update_notification_status_by_id(noti.id, 'temporary-failure', STATISTICS_FAILURE)
|
||||
updated = update_notification_status_by_id(noti.id, 'temporary-failure')
|
||||
if updated:
|
||||
current_app.logger.info(("Timeout period reached for notification ({})"
|
||||
", status has been updated.").format(noti.id))
|
||||
current_app.logger.info(
|
||||
"Timeout period reached for notification ({}), status has been updated.".format(noti.id))
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
current_app.logger.error((
|
||||
|
||||
@@ -27,7 +27,7 @@ from app.dao.notifications_dao import (
|
||||
dao_create_notification,
|
||||
dao_get_notification_statistics_for_service_and_day
|
||||
)
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
from app.dao.services_dao import dao_fetch_service_by_id, dao_fetch_todays_stats_for_service
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.models import (
|
||||
Notification,
|
||||
@@ -46,14 +46,7 @@ def process_job(job_id):
|
||||
|
||||
service = job.service
|
||||
|
||||
stats = dao_get_notification_statistics_for_service_and_day(
|
||||
service_id=service.id,
|
||||
day=job.created_at.strftime(DATE_FORMAT)
|
||||
)
|
||||
|
||||
total_sent = 0
|
||||
if stats:
|
||||
total_sent = stats.emails_requested + stats.sms_requested
|
||||
total_sent = sum(row.count for row in dao_fetch_todays_stats_for_service(service.id))
|
||||
|
||||
if total_sent + job.notification_count > service.message_limit:
|
||||
job.status = 'sending limits exceeded'
|
||||
@@ -212,7 +205,7 @@ def _save_notification(created_at, notification, notification_id, service_id, no
|
||||
api_key_id=api_key_id,
|
||||
key_type=key_type
|
||||
)
|
||||
dao_create_notification(notification_db_object, notification_type)
|
||||
dao_create_notification(notification_db_object)
|
||||
|
||||
|
||||
def service_allowed_to_send_to(recipient, service):
|
||||
|
||||
Reference in New Issue
Block a user