Use short dates when selection notifications for deletion.

This means we will retain notifications for a full week and not
delete records that are 7 x 24 hours older than the time of the run of
the deletion task.

Also the task only needs to run once a day now, so I have changed
the celery config for the deletion tasks.
This commit is contained in:
Adam Shimali
2016-04-25 16:12:46 +01:00
parent 4e4a5abbad
commit 24ea6f1637
4 changed files with 52 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
import math
from sqlalchemy import desc
from sqlalchemy import desc, func
from datetime import (
datetime,
@@ -257,18 +257,20 @@ def filter_query(query, filter_dict=None):
def delete_notifications_created_more_than_a_day_ago(status):
one_day_ago = date.today() - timedelta(days=1)
deleted = db.session.query(Notification).filter(
Notification.created_at < datetime.utcnow() - timedelta(days=1),
func.date(Notification.created_at) < one_day_ago,
Notification.status == status
).delete()
).delete(synchronize_session='fetch')
db.session.commit()
return deleted
def delete_notifications_created_more_than_a_week_ago(status):
seven_days_ago = date.today() - timedelta(days=7)
deleted = db.session.query(Notification).filter(
Notification.created_at < datetime.utcnow() - timedelta(days=7),
func.date(Notification.created_at) < seven_days_ago,
Notification.status == status
).delete()
).delete(synchronize_session='fetch')
db.session.commit()
return deleted