mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Renamed some files and fixed a bug on deleting the failed notifications
This commit is contained in:
@@ -12,7 +12,7 @@ from app.dao.notifications_dao import (
|
||||
)
|
||||
from app.dao.jobs_dao import dao_update_job, dao_get_job_by_id
|
||||
from app.dao.users_dao import delete_codes_older_created_more_than_a_day_ago
|
||||
from app.dao.invited_user_dao import delete_invitations_older_created_more_than_a_day_ago
|
||||
from app.dao.invited_user_dao import delete_invitations_created_more_than_two_days_ago
|
||||
from app.models import (
|
||||
Notification,
|
||||
TEMPLATE_TYPE_EMAIL,
|
||||
@@ -77,7 +77,7 @@ def delete_failed_notifications():
|
||||
def delete_invitations():
|
||||
try:
|
||||
start = datetime.utcnow()
|
||||
deleted = delete_invitations_older_created_more_than_a_day_ago()
|
||||
deleted = delete_invitations_created_more_than_two_days_ago()
|
||||
current_app.logger.info(
|
||||
"Delete job started {} finished {} deleted {} invitations".format(start, datetime.utcnow(), deleted)
|
||||
)
|
||||
|
||||
@@ -21,9 +21,9 @@ 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():
|
||||
def delete_invitations_created_more_than_two_days_ago():
|
||||
deleted = db.session.query(InvitedUser).filter(
|
||||
InvitedUser.created_at <= datetime.utcnow() - timedelta(days=1)
|
||||
InvitedUser.created_at <= datetime.utcnow() - timedelta(days=2)
|
||||
).delete()
|
||||
db.session.commit()
|
||||
return deleted
|
||||
|
||||
@@ -89,7 +89,7 @@ def get_notifications_for_service(service_id, page=1):
|
||||
|
||||
def delete_successful_notifications_created_more_than_a_day_ago():
|
||||
deleted = db.session.query(Notification).filter(
|
||||
Notification.created_at < datetime.utcnow() - timedelta(hours=24),
|
||||
Notification.created_at < datetime.utcnow() - timedelta(days=1),
|
||||
Notification.status == 'sent'
|
||||
).delete()
|
||||
db.session.commit()
|
||||
@@ -98,7 +98,7 @@ def delete_successful_notifications_created_more_than_a_day_ago():
|
||||
|
||||
def delete_failed_notifications_created_more_than_a_week_ago():
|
||||
deleted = db.session.query(Notification).filter(
|
||||
Notification.created_at < datetime.utcnow() - timedelta(hours=24 * 7),
|
||||
Notification.created_at < datetime.utcnow() - timedelta(days=7),
|
||||
Notification.status == 'failed'
|
||||
).delete()
|
||||
db.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user