mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
Scheduled tasks to clean up the database
- tasks run hourly - uses celery beat to schedule the tasks 4 new tasks - delete verify codes (after 1 day) - delete invitations (after 1 day) - delete successful notifications (after 1 day) - delete failed notifications (after 7 days) Delete methods in the DAO classes
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from datetime import datetime, timedelta
|
||||
from app import db
|
||||
|
||||
from app.models import InvitedUser
|
||||
@@ -18,3 +19,11 @@ def get_invited_user_by_id(invited_user_id):
|
||||
|
||||
def get_invited_users_for_service(service_id):
|
||||
return InvitedUser.query.filter_by(service_id=service_id).all()
|
||||
|
||||
|
||||
def delete_invitations_older_created_more_than_a_day_ago():
|
||||
deleted = db.session.query(InvitedUser).filter(
|
||||
InvitedUser.created_at <= datetime.utcnow() - timedelta(days=1)
|
||||
).delete()
|
||||
db.session.commit()
|
||||
return deleted
|
||||
|
||||
Reference in New Issue
Block a user