remove functions to not talk about 7 days

remind us that data retention is flexible
This commit is contained in:
Leo Hemsted
2019-02-26 17:57:35 +00:00
parent a6f5e644b6
commit 38f0ea6cca
5 changed files with 35 additions and 35 deletions

View File

@@ -16,14 +16,14 @@ from app.celery.service_callback_tasks import (
create_delivery_status_callback_data, create_delivery_status_callback_data,
) )
from app.config import QueueNames from app.config import QueueNames
from app.dao.inbound_sms_dao import delete_inbound_sms_created_more_than_a_week_ago from app.dao.inbound_sms_dao import delete_inbound_sms_older_than_retention
from app.dao.jobs_dao import ( from app.dao.jobs_dao import (
dao_get_jobs_older_than_data_retention, dao_get_jobs_older_than_data_retention,
dao_archive_job dao_archive_job
) )
from app.dao.notifications_dao import ( from app.dao.notifications_dao import (
dao_timeout_notifications, dao_timeout_notifications,
delete_notifications_created_more_than_a_week_ago_by_type, delete_notifications_older_than_retention_by_type,
) )
from app.dao.service_callback_api_dao import get_service_delivery_status_callback_api_for_service from app.dao.service_callback_api_dao import get_service_delivery_status_callback_api_for_service
from app.exceptions import NotificationTechnicalFailureException from app.exceptions import NotificationTechnicalFailureException
@@ -64,10 +64,10 @@ def _remove_csv_files(job_types):
@notify_celery.task(name="delete-sms-notifications") @notify_celery.task(name="delete-sms-notifications")
@cronitor("delete-sms-notifications") @cronitor("delete-sms-notifications")
@statsd(namespace="tasks") @statsd(namespace="tasks")
def delete_sms_notifications_older_than_seven_days(): def delete_sms_notifications_older_than_retention():
try: try:
start = datetime.utcnow() start = datetime.utcnow()
deleted = delete_notifications_created_more_than_a_week_ago_by_type('sms') deleted = delete_notifications_older_than_retention_by_type('sms')
current_app.logger.info( current_app.logger.info(
"Delete {} job started {} finished {} deleted {} sms notifications".format( "Delete {} job started {} finished {} deleted {} sms notifications".format(
'sms', 'sms',
@@ -84,10 +84,10 @@ def delete_sms_notifications_older_than_seven_days():
@notify_celery.task(name="delete-email-notifications") @notify_celery.task(name="delete-email-notifications")
@cronitor("delete-email-notifications") @cronitor("delete-email-notifications")
@statsd(namespace="tasks") @statsd(namespace="tasks")
def delete_email_notifications_older_than_seven_days(): def delete_email_notifications_older_than_retention():
try: try:
start = datetime.utcnow() start = datetime.utcnow()
deleted = delete_notifications_created_more_than_a_week_ago_by_type('email') deleted = delete_notifications_older_than_retention_by_type('email')
current_app.logger.info( current_app.logger.info(
"Delete {} job started {} finished {} deleted {} email notifications".format( "Delete {} job started {} finished {} deleted {} email notifications".format(
'email', 'email',
@@ -104,10 +104,10 @@ def delete_email_notifications_older_than_seven_days():
@notify_celery.task(name="delete-letter-notifications") @notify_celery.task(name="delete-letter-notifications")
@cronitor("delete-letter-notifications") @cronitor("delete-letter-notifications")
@statsd(namespace="tasks") @statsd(namespace="tasks")
def delete_letter_notifications_older_than_seven_days(): def delete_letter_notifications_older_than_retention():
try: try:
start = datetime.utcnow() start = datetime.utcnow()
deleted = delete_notifications_created_more_than_a_week_ago_by_type('letter') deleted = delete_notifications_older_than_retention_by_type('letter')
current_app.logger.info( current_app.logger.info(
"Delete {} job started {} finished {} deleted {} letter notifications".format( "Delete {} job started {} finished {} deleted {} letter notifications".format(
'letter', 'letter',
@@ -190,10 +190,10 @@ def send_total_sent_notifications_to_performance_platform(day):
@notify_celery.task(name="delete-inbound-sms") @notify_celery.task(name="delete-inbound-sms")
@cronitor("delete-inbound-sms") @cronitor("delete-inbound-sms")
@statsd(namespace="tasks") @statsd(namespace="tasks")
def delete_inbound_sms_older_than_seven_days(): def delete_inbound_sms():
try: try:
start = datetime.utcnow() start = datetime.utcnow()
deleted = delete_inbound_sms_created_more_than_a_week_ago() deleted = delete_inbound_sms_older_than_retention()
current_app.logger.info( current_app.logger.info(
"Delete inbound sms job started {} finished {} deleted {} inbound sms notifications".format( "Delete inbound sms job started {} finished {} deleted {} inbound sms notifications".format(
start, start,

View File

@@ -293,7 +293,7 @@ def _filter_query(query, filter_dict=None):
@statsd(namespace="dao") @statsd(namespace="dao")
def delete_notifications_created_more_than_a_week_ago_by_type(notification_type, qry_limit=10000): def delete_notifications_older_than_retention_by_type(notification_type, qry_limit=10000):
current_app.logger.info( current_app.logger.info(
'Deleting {} notifications for services with flexible data retention'.format(notification_type)) 'Deleting {} notifications for services with flexible data retention'.format(notification_type))

View File

@@ -11,10 +11,10 @@ from notifications_utils.clients.zendesk.zendesk_client import ZendeskClient
from app.celery import nightly_tasks from app.celery import nightly_tasks
from app.celery.nightly_tasks import ( from app.celery.nightly_tasks import (
delete_dvla_response_files_older_than_seven_days, delete_dvla_response_files_older_than_seven_days,
delete_email_notifications_older_than_seven_days, delete_email_notifications_older_than_retention,
delete_inbound_sms_older_than_seven_days, delete_inbound_sms,
delete_letter_notifications_older_than_seven_days, delete_letter_notifications_older_than_retention,
delete_sms_notifications_older_than_seven_days, delete_sms_notifications_older_than_retention,
raise_alert_if_letter_notifications_still_sending, raise_alert_if_letter_notifications_still_sending,
remove_letter_csv_files, remove_letter_csv_files,
remove_sms_email_csv_files, remove_sms_email_csv_files,
@@ -157,21 +157,21 @@ def test_remove_csv_files_filters_by_type(mocker, sample_service):
def test_should_call_delete_sms_notifications_more_than_week_in_task(notify_api, mocker): def test_should_call_delete_sms_notifications_more_than_week_in_task(notify_api, mocker):
mocked = mocker.patch('app.celery.nightly_tasks.delete_notifications_created_more_than_a_week_ago_by_type') mocked = mocker.patch('app.celery.nightly_tasks.delete_notifications_older_than_retention_by_type')
delete_sms_notifications_older_than_seven_days() delete_sms_notifications_older_than_retention()
mocked.assert_called_once_with('sms') mocked.assert_called_once_with('sms')
def test_should_call_delete_email_notifications_more_than_week_in_task(notify_api, mocker): def test_should_call_delete_email_notifications_more_than_week_in_task(notify_api, mocker):
mocked_notifications = mocker.patch( mocked_notifications = mocker.patch(
'app.celery.nightly_tasks.delete_notifications_created_more_than_a_week_ago_by_type') 'app.celery.nightly_tasks.delete_notifications_older_than_retention_by_type')
delete_email_notifications_older_than_seven_days() delete_email_notifications_older_than_retention()
mocked_notifications.assert_called_once_with('email') mocked_notifications.assert_called_once_with('email')
def test_should_call_delete_letter_notifications_more_than_week_in_task(notify_api, mocker): def test_should_call_delete_letter_notifications_more_than_week_in_task(notify_api, mocker):
mocked = mocker.patch('app.celery.nightly_tasks.delete_notifications_created_more_than_a_week_ago_by_type') mocked = mocker.patch('app.celery.nightly_tasks.delete_notifications_older_than_retention_by_type')
delete_letter_notifications_older_than_seven_days() delete_letter_notifications_older_than_retention()
mocked.assert_called_once_with('letter') mocked.assert_called_once_with('letter')
@@ -291,10 +291,10 @@ def test_send_total_sent_notifications_to_performance_platform_calls_with_correc
]) ])
def test_should_call_delete_inbound_sms_older_than_seven_days(notify_api, mocker): def test_should_call_delete_inbound_sms(notify_api, mocker):
mocker.patch('app.celery.nightly_tasks.delete_inbound_sms_created_more_than_a_week_ago') mocker.patch('app.celery.nightly_tasks.delete_inbound_sms_older_than_retention')
delete_inbound_sms_older_than_seven_days() delete_inbound_sms()
assert nightly_tasks.delete_inbound_sms_created_more_than_a_week_ago.call_count == 1 assert nightly_tasks.delete_inbound_sms_older_than_retention.call_count == 1
@freeze_time('2017-01-01 10:00:00') @freeze_time('2017-01-01 10:00:00')

View File

@@ -19,7 +19,7 @@ from app.dao.notifications_dao import (
dao_timeout_notifications, dao_timeout_notifications,
dao_update_notification, dao_update_notification,
dao_update_notifications_by_reference, dao_update_notifications_by_reference,
delete_notifications_created_more_than_a_week_ago_by_type, delete_notifications_older_than_retention_by_type,
get_notification_by_id, get_notification_by_id,
get_notification_for_job, get_notification_for_job,
get_notification_with_personalisation, get_notification_with_personalisation,
@@ -79,7 +79,7 @@ def test_should_have_decorated_notifications_dao_functions():
assert get_notification_with_personalisation.__wrapped__.__name__ == 'get_notification_with_personalisation' # noqa assert get_notification_with_personalisation.__wrapped__.__name__ == 'get_notification_with_personalisation' # noqa
assert get_notifications_for_service.__wrapped__.__name__ == 'get_notifications_for_service' # noqa assert get_notifications_for_service.__wrapped__.__name__ == 'get_notifications_for_service' # noqa
assert get_notification_by_id.__wrapped__.__name__ == 'get_notification_by_id' # noqa assert get_notification_by_id.__wrapped__.__name__ == 'get_notification_by_id' # noqa
assert delete_notifications_created_more_than_a_week_ago_by_type.__wrapped__.__name__ == 'delete_notifications_created_more_than_a_week_ago_by_type' # noqa assert delete_notifications_older_than_retention_by_type.__wrapped__.__name__ == 'delete_notifications_older_than_retention_by_type' # noqa
assert dao_delete_notifications_and_history_by_id.__wrapped__.__name__ == 'dao_delete_notifications_and_history_by_id' # noqa assert dao_delete_notifications_and_history_by_id.__wrapped__.__name__ == 'dao_delete_notifications_and_history_by_id' # noqa

View File

@@ -6,7 +6,7 @@ from datetime import (
import pytest import pytest
from flask import current_app from flask import current_app
from freezegun import freeze_time from freezegun import freeze_time
from app.dao.notifications_dao import delete_notifications_created_more_than_a_week_ago_by_type from app.dao.notifications_dao import delete_notifications_older_than_retention_by_type
from app.models import Notification, NotificationHistory from app.models import Notification, NotificationHistory
from tests.app.db import ( from tests.app.db import (
create_template, create_template,
@@ -48,7 +48,7 @@ def test_should_delete_notifications_by_type_after_seven_days(
assert len(all_notifications) == 30 assert len(all_notifications) == 30
# Records from before 3rd should be deleted # Records from before 3rd should be deleted
with freeze_time(delete_run_time): with freeze_time(delete_run_time):
delete_notifications_created_more_than_a_week_ago_by_type(notification_type) delete_notifications_older_than_retention_by_type(notification_type)
remaining_sms_notifications = Notification.query.filter_by(notification_type='sms').all() remaining_sms_notifications = Notification.query.filter_by(notification_type='sms').all()
remaining_letter_notifications = Notification.query.filter_by(notification_type='letter').all() remaining_letter_notifications = Notification.query.filter_by(notification_type='letter').all()
remaining_email_notifications = Notification.query.filter_by(notification_type='email').all() remaining_email_notifications = Notification.query.filter_by(notification_type='email').all()
@@ -77,7 +77,7 @@ def test_should_not_delete_notification_history(sample_service, notification_typ
create_notification(template=letter_template, status='permanent-failure') create_notification(template=letter_template, status='permanent-failure')
assert Notification.query.count() == 3 assert Notification.query.count() == 3
assert NotificationHistory.query.count() == 3 assert NotificationHistory.query.count() == 3
delete_notifications_created_more_than_a_week_ago_by_type(notification_type) delete_notifications_older_than_retention_by_type(notification_type)
assert Notification.query.count() == 2 assert Notification.query.count() == 2
assert NotificationHistory.query.count() == 3 assert NotificationHistory.query.count() == 3
@@ -109,7 +109,7 @@ def test_delete_notifications_for_days_of_retention(sample_service, notification
created_at=datetime.utcnow() - timedelta(days=8)) created_at=datetime.utcnow() - timedelta(days=8))
create_service_data_retention(service_id=sample_service.id, notification_type=notification_type) create_service_data_retention(service_id=sample_service.id, notification_type=notification_type)
assert len(Notification.query.all()) == 9 assert len(Notification.query.all()) == 9
delete_notifications_created_more_than_a_week_ago_by_type(notification_type) delete_notifications_older_than_retention_by_type(notification_type)
assert len(Notification.query.all()) == 7 assert len(Notification.query.all()) == 7
assert len(Notification.query.filter_by(notification_type=notification_type).all()) == 1 assert len(Notification.query.filter_by(notification_type=notification_type).all()) == 1
if notification_type == 'letter': if notification_type == 'letter':
@@ -146,7 +146,7 @@ def test_delete_notifications_keep_data_for_days_of_retention_is_longer(sample_s
create_notification(template=default_letter_template, status='temporary-failure', create_notification(template=default_letter_template, status='temporary-failure',
created_at=datetime.utcnow() - timedelta(days=8)) created_at=datetime.utcnow() - timedelta(days=8))
assert len(Notification.query.all()) == 9 assert len(Notification.query.all()) == 9
delete_notifications_created_more_than_a_week_ago_by_type(notification_type) delete_notifications_older_than_retention_by_type(notification_type)
assert len(Notification.query.filter_by().all()) == 8 assert len(Notification.query.filter_by().all()) == 8
assert len(Notification.query.filter_by(notification_type=notification_type).all()) == 2 assert len(Notification.query.filter_by(notification_type=notification_type).all()) == 2
if notification_type == 'letter': if notification_type == 'letter':
@@ -171,7 +171,7 @@ def test_delete_notifications_delete_notification_type_for_default_time_if_no_da
create_notification(template=letter_template, status='temporary-failure', create_notification(template=letter_template, status='temporary-failure',
created_at=datetime.utcnow() - timedelta(days=14)) created_at=datetime.utcnow() - timedelta(days=14))
assert len(Notification.query.all()) == 6 assert len(Notification.query.all()) == 6
delete_notifications_created_more_than_a_week_ago_by_type('email') delete_notifications_older_than_retention_by_type('email')
assert len(Notification.query.filter_by().all()) == 5 assert len(Notification.query.filter_by().all()) == 5
assert len(Notification.query.filter_by(notification_type='email').all()) == 1 assert len(Notification.query.filter_by(notification_type='email').all()) == 1
@@ -182,7 +182,7 @@ def test_delete_notifications_does_try_to_delete_from_s3_when_letter_has_not_bee
create_notification(template=letter_template, status='sending', create_notification(template=letter_template, status='sending',
reference='LETTER_REF') reference='LETTER_REF')
delete_notifications_created_more_than_a_week_ago_by_type('email', qry_limit=1) delete_notifications_older_than_retention_by_type('email', qry_limit=1)
mock_get_s3.assert_not_called() mock_get_s3.assert_not_called()
@@ -196,7 +196,7 @@ def test_delete_notifications_calls_subquery(
create_notification(template=sms_template, created_at=datetime.now() - timedelta(days=8)) create_notification(template=sms_template, created_at=datetime.now() - timedelta(days=8))
assert Notification.query.count() == 3 assert Notification.query.count() == 3
delete_notifications_created_more_than_a_week_ago_by_type('sms', qry_limit=1) delete_notifications_older_than_retention_by_type('sms', qry_limit=1)
assert Notification.query.count() == 0 assert Notification.query.count() == 0