mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Adds a query to timeout the job counts.
After three days we timeout the notifications that we have not received a receipt for. In the same way we bump the failed count to match the job count if there is a descepenecy. We do this after the same period that we do for notifications.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from flask import current_app
|
||||
from sqlalchemy.exc import IntegrityError, SQLAlchemyError
|
||||
@@ -16,6 +16,29 @@ from app.models import (
|
||||
from app.statsd_decorators import statsd
|
||||
|
||||
|
||||
@transactional
|
||||
def timeout_job_counts(notifications_type, timeout_start):
|
||||
sent = columns(notifications_type, 'sent')
|
||||
delivered = columns(notifications_type, 'delivered')
|
||||
failed = columns(notifications_type, 'failed')
|
||||
|
||||
query = JobStatistics.query.filter(
|
||||
JobStatistics.created_at < timeout_start,
|
||||
sent != failed + delivered
|
||||
)
|
||||
return query.update(
|
||||
{failed: sent - delivered}, synchronize_session=False
|
||||
)
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def timeout_job_statistics(timeout_period):
|
||||
timeout_start = datetime.utcnow() - timedelta(seconds=timeout_period)
|
||||
sms_count = timeout_job_counts(SMS_TYPE, timeout_start)
|
||||
email_count = timeout_job_counts(EMAIL_TYPE, timeout_start)
|
||||
return sms_count + email_count
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def create_or_update_job_sending_statistics(notification):
|
||||
if __update_job_stats_sent_count(notification) == 0:
|
||||
|
||||
Reference in New Issue
Block a user