Delete send-scheduled-notifications task

This was added a few years ago, but never used.
This commit is contained in:
Katie Smith
2020-04-01 13:11:39 +01:00
parent e07dea27e1
commit bfd40a843c
4 changed files with 0 additions and 84 deletions

View File

@@ -25,8 +25,6 @@ from app.dao.jobs_dao import (
) )
from app.dao.jobs_dao import dao_update_job from app.dao.jobs_dao import dao_update_job
from app.dao.notifications_dao import ( from app.dao.notifications_dao import (
dao_get_scheduled_notifications,
set_scheduled_notification_to_processed,
notifications_not_yet_sent, notifications_not_yet_sent,
dao_precompiled_letters_still_pending_virus_check, dao_precompiled_letters_still_pending_virus_check,
dao_old_letters_with_created_status, dao_old_letters_with_created_status,
@@ -62,21 +60,6 @@ def run_scheduled_jobs():
raise raise
@notify_celery.task(name='send-scheduled-notifications')
@statsd(namespace="tasks")
def send_scheduled_notifications():
try:
scheduled_notifications = dao_get_scheduled_notifications()
for notification in scheduled_notifications:
send_notification_to_queue(notification, notification.service.research_mode)
set_scheduled_notification_to_processed(notification.id)
current_app.logger.info(
"Sent {} scheduled notifications to the provider queue".format(len(scheduled_notifications)))
except SQLAlchemyError:
current_app.logger.exception("Failed to send scheduled notifications")
raise
@notify_celery.task(name="delete-verify-codes") @notify_celery.task(name="delete-verify-codes")
@statsd(namespace="tasks") @statsd(namespace="tasks")
def delete_verify_codes(): def delete_verify_codes():

View File

@@ -33,7 +33,6 @@ from app.models import (
Notification, Notification,
NotificationHistory, NotificationHistory,
ProviderDetails, ProviderDetails,
ScheduledNotification,
KEY_TYPE_NORMAL, KEY_TYPE_NORMAL,
KEY_TYPE_TEST, KEY_TYPE_TEST,
LETTER_TYPE, LETTER_TYPE,
@@ -652,26 +651,6 @@ def dao_created_scheduled_notification(scheduled_notification):
db.session.commit() db.session.commit()
@statsd(namespace="dao")
def dao_get_scheduled_notifications():
notifications = Notification.query.join(
ScheduledNotification
).filter(
ScheduledNotification.scheduled_for < datetime.utcnow(),
ScheduledNotification.pending).all()
return notifications
def set_scheduled_notification_to_processed(notification_id):
db.session.query(ScheduledNotification).filter(
ScheduledNotification.notification_id == notification_id
).update(
{'pending': False}
)
db.session.commit()
def dao_get_total_notifications_sent_per_day_for_performance_platform(start_date, end_date): def dao_get_total_notifications_sent_per_day_for_performance_platform(start_date, end_date):
""" """
SELECT SELECT

View File

@@ -12,7 +12,6 @@ from app.celery.scheduled_tasks import (
delete_invitations, delete_invitations,
delete_verify_codes, delete_verify_codes,
run_scheduled_jobs, run_scheduled_jobs,
send_scheduled_notifications,
replay_created_notifications, replay_created_notifications,
check_precompiled_letter_state, check_precompiled_letter_state,
check_templated_letter_state, check_templated_letter_state,
@@ -22,7 +21,6 @@ from app.celery.scheduled_tasks import (
) )
from app.config import QueueNames, TaskNames, Config from app.config import QueueNames, TaskNames, Config
from app.dao.jobs_dao import dao_get_job_by_id from app.dao.jobs_dao import dao_get_job_by_id
from app.dao.notifications_dao import dao_get_scheduled_notifications
from app.dao.provider_details_dao import get_provider_details_by_identifier from app.dao.provider_details_dao import get_provider_details_by_identifier
from app.models import ( from app.models import (
JOB_STATUS_IN_PROGRESS, JOB_STATUS_IN_PROGRESS,
@@ -143,24 +141,6 @@ def test_switch_current_sms_provider_on_slow_delivery_does_nothing_if_no_need(
assert mock_reduce.called is False assert mock_reduce.called is False
@freeze_time("2017-05-01 14:00:00")
def test_should_send_all_scheduled_notifications_to_deliver_queue(sample_template, mocker):
mocked = mocker.patch('app.celery.provider_tasks.deliver_sms')
message_to_deliver = create_notification(template=sample_template, scheduled_for="2017-05-01 13:15")
create_notification(template=sample_template, scheduled_for="2017-05-01 10:15", status='delivered')
create_notification(template=sample_template)
create_notification(template=sample_template, scheduled_for="2017-05-01 14:15")
scheduled_notifications = dao_get_scheduled_notifications()
assert len(scheduled_notifications) == 1
send_scheduled_notifications()
mocked.apply_async.assert_called_once_with([str(message_to_deliver.id)], queue='send-sms-tasks')
scheduled_notifications = dao_get_scheduled_notifications()
assert not scheduled_notifications
def test_check_job_status_task_raises_job_incomplete_error(mocker, sample_template): def test_check_job_status_task_raises_job_incomplete_error(mocker, sample_template):
mock_celery = mocker.patch('app.celery.tasks.notify_celery.send_task') mock_celery = mocker.patch('app.celery.tasks.notify_celery.send_task')
job = create_job(template=sample_template, notification_count=3, job = create_job(template=sample_template, notification_count=3,

View File

@@ -15,7 +15,6 @@ from app.dao.notifications_dao import (
dao_get_last_notification_added_for_job_id, dao_get_last_notification_added_for_job_id,
dao_get_notifications_by_recipient_or_reference, dao_get_notifications_by_recipient_or_reference,
dao_get_notification_count_for_job_id, dao_get_notification_count_for_job_id,
dao_get_scheduled_notifications,
dao_timeout_notifications, dao_timeout_notifications,
dao_update_notification, dao_update_notification,
dao_update_notifications_by_reference, dao_update_notifications_by_reference,
@@ -26,7 +25,6 @@ from app.dao.notifications_dao import (
get_notifications_for_job, get_notifications_for_job,
get_notifications_for_service, get_notifications_for_service,
is_delivery_slow_for_providers, is_delivery_slow_for_providers,
set_scheduled_notification_to_processed,
update_notification_status_by_id, update_notification_status_by_id,
update_notification_status_by_reference, update_notification_status_by_reference,
dao_get_notification_by_reference, dao_get_notification_by_reference,
@@ -1358,30 +1356,6 @@ def test_dao_created_scheduled_notification(sample_notification):
assert saved_notification[0].scheduled_for == datetime(2017, 1, 5, 14, 15) assert saved_notification[0].scheduled_for == datetime(2017, 1, 5, 14, 15)
def test_dao_get_scheduled_notifications(sample_template):
notification_1 = create_notification(template=sample_template, scheduled_for='2017-05-05 14:15',
status='created')
create_notification(template=sample_template, scheduled_for='2017-05-04 14:15', status='delivered')
create_notification(template=sample_template, status='created')
scheduled_notifications = dao_get_scheduled_notifications()
assert len(scheduled_notifications) == 1
assert scheduled_notifications[0].id == notification_1.id
assert scheduled_notifications[0].scheduled_notification.pending
def test_set_scheduled_notification_to_processed(sample_template):
notification_1 = create_notification(template=sample_template, scheduled_for='2017-05-05 14:15',
status='created')
scheduled_notifications = dao_get_scheduled_notifications()
assert len(scheduled_notifications) == 1
assert scheduled_notifications[0].id == notification_1.id
assert scheduled_notifications[0].scheduled_notification.pending
set_scheduled_notification_to_processed(notification_1.id)
scheduled_notifications = dao_get_scheduled_notifications()
assert not scheduled_notifications
def test_dao_get_notifications_by_to_field_filters_status(sample_template): def test_dao_get_notifications_by_to_field_filters_status(sample_template):
notification = create_notification( notification = create_notification(
template=sample_template, to_field='+447700900855', template=sample_template, to_field='+447700900855',