cleanup pending notifications

This commit is contained in:
Kenneth Kehl
2025-01-08 08:44:49 -08:00
parent 31198824cd
commit 0d1a98914a
5 changed files with 49 additions and 1 deletions

View File

@@ -780,3 +780,20 @@ def dao_update_delivery_receipts(receipts, delivered):
f"#loadtestperformance batch update query time: \
updated {len(receipts)} notification in {elapsed_time} ms"
)
def dao_close_out_delivery_receipts():
THREE_DAYS_AGO = utc_now() - timedelta(minutes=3)
stmt = (
update(Notification)
.where(
Notification.status == NotificationStatus.PENDING,
Notification.sent_at < THREE_DAYS_AGO,
)
.values(status=NotificationStatus.FAILED, provider_response="Technical Failure")
)
result = db.session.execute(stmt)
current_app.logger.info(
f"Marked {result.rowcount} notifications as technical failures"
)
db.session.commit()