mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 14:31:57 -05:00
Tightened the error checking.
- Looks now for a specific Integrity error, not a generic SQLAlchemy error when checking for an insert failure - If the update fails post an insert error, then there is an issue so raise an exception so tasks can be retried.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from flask import current_app
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.exc import IntegrityError, SQLAlchemyError
|
||||
|
||||
from app import db
|
||||
from app.dao.dao_utils import transactional
|
||||
@@ -15,14 +15,14 @@ from app.statsd_decorators import statsd
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
@transactional
|
||||
def create_or_update_job_sending_statistics(notification):
|
||||
if __update_job_stats_sent_count(notification) == 0:
|
||||
try:
|
||||
__insert_job_stats(notification)
|
||||
except SQLAlchemyError as e:
|
||||
except IntegrityError as e:
|
||||
current_app.logger.exception(e)
|
||||
__update_job_stats_sent_count(notification)
|
||||
if __update_job_stats_sent_count(notification) == 0:
|
||||
raise SQLAlchemyError("Failed to create job statistics for {}".format(notification.job_id))
|
||||
|
||||
|
||||
def __update_job_stats_sent_count(notification):
|
||||
@@ -39,6 +39,7 @@ def __update_job_stats_sent_count(notification):
|
||||
).update(update)
|
||||
|
||||
|
||||
@transactional
|
||||
def __insert_job_stats(notification):
|
||||
|
||||
stats = JobStatistics(
|
||||
|
||||
Reference in New Issue
Block a user