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:
Martyn Inglis
2017-05-11 15:22:43 +01:00
parent e993a91a11
commit b519321798
2 changed files with 123 additions and 3 deletions

View File

@@ -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: