mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 17:01:35 -05:00
Add task to delete inbound sms everyday at 1am
This commit is contained in:
@@ -9,6 +9,7 @@ from sqlalchemy.exc import SQLAlchemyError
|
|||||||
from app.aws import s3
|
from app.aws import s3
|
||||||
from app import notify_celery
|
from app import notify_celery
|
||||||
from app import performance_platform_client
|
from app import performance_platform_client
|
||||||
|
from app.dao.inbound_sms_dao import delete_inbound_sms_created_more_than_a_week_ago
|
||||||
from app.dao.invited_user_dao import delete_invitations_created_more_than_two_days_ago
|
from app.dao.invited_user_dao import delete_invitations_created_more_than_two_days_ago
|
||||||
from app.dao.jobs_dao import dao_set_scheduled_jobs_to_pending, dao_get_jobs_older_than_limited_by
|
from app.dao.jobs_dao import dao_set_scheduled_jobs_to_pending, dao_get_jobs_older_than_limited_by
|
||||||
from app.dao.notifications_dao import (
|
from app.dao.notifications_dao import (
|
||||||
@@ -226,3 +227,21 @@ def timeout_job_statistics():
|
|||||||
if updated:
|
if updated:
|
||||||
current_app.logger.info(
|
current_app.logger.info(
|
||||||
"Timeout period reached for {} job statistics, failure count has been updated.".format(updated))
|
"Timeout period reached for {} job statistics, failure count has been updated.".format(updated))
|
||||||
|
|
||||||
|
|
||||||
|
@notify_celery.task(name="delete-inbound-sms")
|
||||||
|
@statsd(namespace="tasks")
|
||||||
|
def delete_inbound_sms_older_than_seven_days():
|
||||||
|
try:
|
||||||
|
start = datetime.utcnow()
|
||||||
|
deleted = delete_inbound_sms_created_more_than_a_week_ago()
|
||||||
|
current_app.logger.info(
|
||||||
|
"Delete inbound sms job started {} finished {} deleted {} inbound sms notifications".format(
|
||||||
|
start,
|
||||||
|
datetime.utcnow(),
|
||||||
|
deleted
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except SQLAlchemyError as e:
|
||||||
|
current_app.logger.exception("Failed to delete inbound sms notifications")
|
||||||
|
raise
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from datetime import timedelta
|
|||||||
from celery.schedules import crontab
|
from celery.schedules import crontab
|
||||||
from kombu import Exchange, Queue
|
from kombu import Exchange, Queue
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from app.models import KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST
|
from app.models import KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST
|
||||||
|
|
||||||
if os.environ.get('VCAP_SERVICES'):
|
if os.environ.get('VCAP_SERVICES'):
|
||||||
@@ -168,6 +169,11 @@ class Config(object):
|
|||||||
'schedule': crontab(minute=40, hour=0),
|
'schedule': crontab(minute=40, hour=0),
|
||||||
'options': {'queue': QueueNames.PERIODIC}
|
'options': {'queue': QueueNames.PERIODIC}
|
||||||
},
|
},
|
||||||
|
'delete-inbound-sms': {
|
||||||
|
'task': 'delete-inbound-sms',
|
||||||
|
'schedule': crontab(minute=0, hour=1),
|
||||||
|
'options': {'queue': QueueNames.PERIODIC}
|
||||||
|
},
|
||||||
'send-daily-performance-platform-stats': {
|
'send-daily-performance-platform-stats': {
|
||||||
'task': 'send-daily-performance-platform-stats',
|
'task': 'send-daily-performance-platform-stats',
|
||||||
'schedule': crontab(minute=0, hour=2),
|
'schedule': crontab(minute=0, hour=2),
|
||||||
|
|||||||
@@ -5,19 +5,23 @@ from functools import partial
|
|||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
from app.celery.scheduled_tasks import s3, timeout_job_statistics, delete_sms_notifications_older_than_seven_days, \
|
|
||||||
delete_letter_notifications_older_than_seven_days, delete_email_notifications_older_than_seven_days, \
|
|
||||||
send_scheduled_notifications
|
|
||||||
from app.celery import scheduled_tasks
|
from app.celery import scheduled_tasks
|
||||||
from app.celery.scheduled_tasks import (
|
from app.celery.scheduled_tasks import (
|
||||||
|
delete_email_notifications_older_than_seven_days,
|
||||||
|
delete_inbound_sms_older_than_seven_days,
|
||||||
|
delete_invitations,
|
||||||
|
delete_notifications_created_more_than_a_week_ago_by_type,
|
||||||
|
delete_letter_notifications_older_than_seven_days,
|
||||||
|
delete_sms_notifications_older_than_seven_days,
|
||||||
delete_verify_codes,
|
delete_verify_codes,
|
||||||
remove_csv_files,
|
remove_csv_files,
|
||||||
delete_notifications_created_more_than_a_week_ago_by_type,
|
|
||||||
delete_invitations,
|
|
||||||
timeout_notifications,
|
|
||||||
run_scheduled_jobs,
|
run_scheduled_jobs,
|
||||||
|
s3,
|
||||||
send_daily_performance_platform_stats,
|
send_daily_performance_platform_stats,
|
||||||
switch_current_sms_provider_on_slow_delivery
|
send_scheduled_notifications,
|
||||||
|
switch_current_sms_provider_on_slow_delivery,
|
||||||
|
timeout_job_statistics,
|
||||||
|
timeout_notifications
|
||||||
)
|
)
|
||||||
from app.clients.performance_platform.performance_platform_client import PerformancePlatformClient
|
from app.clients.performance_platform.performance_platform_client import PerformancePlatformClient
|
||||||
from app.dao.jobs_dao import dao_get_job_by_id
|
from app.dao.jobs_dao import dao_get_job_by_id
|
||||||
@@ -71,7 +75,8 @@ def prepare_current_provider(restore_provider_details):
|
|||||||
|
|
||||||
def test_should_have_decorated_tasks_functions():
|
def test_should_have_decorated_tasks_functions():
|
||||||
assert delete_verify_codes.__wrapped__.__name__ == 'delete_verify_codes'
|
assert delete_verify_codes.__wrapped__.__name__ == 'delete_verify_codes'
|
||||||
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_created_more_than_a_week_ago_by_type.__wrapped__.__name__ == \
|
||||||
|
'delete_notifications_created_more_than_a_week_ago_by_type'
|
||||||
assert timeout_notifications.__wrapped__.__name__ == 'timeout_notifications'
|
assert timeout_notifications.__wrapped__.__name__ == 'timeout_notifications'
|
||||||
assert delete_invitations.__wrapped__.__name__ == 'delete_invitations'
|
assert delete_invitations.__wrapped__.__name__ == 'delete_invitations'
|
||||||
assert run_scheduled_jobs.__wrapped__.__name__ == 'run_scheduled_jobs'
|
assert run_scheduled_jobs.__wrapped__.__name__ == 'run_scheduled_jobs'
|
||||||
@@ -79,6 +84,8 @@ def test_should_have_decorated_tasks_functions():
|
|||||||
assert send_daily_performance_platform_stats.__wrapped__.__name__ == 'send_daily_performance_platform_stats'
|
assert send_daily_performance_platform_stats.__wrapped__.__name__ == 'send_daily_performance_platform_stats'
|
||||||
assert switch_current_sms_provider_on_slow_delivery.__wrapped__.__name__ == \
|
assert switch_current_sms_provider_on_slow_delivery.__wrapped__.__name__ == \
|
||||||
'switch_current_sms_provider_on_slow_delivery'
|
'switch_current_sms_provider_on_slow_delivery'
|
||||||
|
assert delete_inbound_sms_older_than_seven_days.__wrapped__.__name__ == \
|
||||||
|
'delete_inbound_sms_older_than_seven_days'
|
||||||
|
|
||||||
|
|
||||||
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):
|
||||||
@@ -440,3 +447,9 @@ def test_timeout_job_statistics_called_with_notification_timeout(notify_api, moc
|
|||||||
dao_mock = mocker.patch('app.celery.scheduled_tasks.dao_timeout_job_statistics')
|
dao_mock = mocker.patch('app.celery.scheduled_tasks.dao_timeout_job_statistics')
|
||||||
timeout_job_statistics()
|
timeout_job_statistics()
|
||||||
dao_mock.assert_called_once_with(999)
|
dao_mock.assert_called_once_with(999)
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_call_delete_inbound_sms_older_than_seven_days(notify_api, mocker):
|
||||||
|
mocker.patch('app.celery.scheduled_tasks.delete_inbound_sms_created_more_than_a_week_ago')
|
||||||
|
delete_inbound_sms_older_than_seven_days()
|
||||||
|
assert scheduled_tasks.delete_inbound_sms_created_more_than_a_week_ago.call_count == 1
|
||||||
|
|||||||
Reference in New Issue
Block a user