mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Call publish-govuk-alerts task when alert expires
The `auto-expire-broadcast-messages` task checks for expired broadcasts at five minute intervals. This change now calls the `publish-govuk-alerts` task in govuk-alerts if there are expired broadcasts so that the site is updated. Co-authored-by: Katie Smith <katie.smith@digital.cabinet-office.gov.uk>
This commit is contained in:
committed by
Katie Smith
parent
04bfd6bfdb
commit
1b6f9505da
@@ -16,7 +16,7 @@ from app.celery.tasks import (
|
|||||||
process_job,
|
process_job,
|
||||||
process_row,
|
process_row,
|
||||||
)
|
)
|
||||||
from app.config import QueueNames
|
from app.config import QueueNames, TaskNames
|
||||||
from app.dao.invited_org_user_dao import (
|
from app.dao.invited_org_user_dao import (
|
||||||
delete_org_invitations_created_more_than_two_days_ago,
|
delete_org_invitations_created_more_than_two_days_ago,
|
||||||
)
|
)
|
||||||
@@ -322,9 +322,15 @@ def auto_expire_broadcast_messages():
|
|||||||
expired_broadcasts = BroadcastMessage.query.filter(
|
expired_broadcasts = BroadcastMessage.query.filter(
|
||||||
BroadcastMessage.finishes_at <= datetime.now(),
|
BroadcastMessage.finishes_at <= datetime.now(),
|
||||||
BroadcastMessage.status == BroadcastStatusType.BROADCASTING,
|
BroadcastMessage.status == BroadcastStatusType.BROADCASTING,
|
||||||
)
|
).all()
|
||||||
|
|
||||||
for broadcast in expired_broadcasts:
|
for broadcast in expired_broadcasts:
|
||||||
broadcast.status = BroadcastStatusType.COMPLETED
|
broadcast.status = BroadcastStatusType.COMPLETED
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
if expired_broadcasts:
|
||||||
|
notify_celery.send_task(
|
||||||
|
name=TaskNames.PUBLISH_GOVUK_ALERTS,
|
||||||
|
queue=QueueNames.GOVUK_ALERTS
|
||||||
|
)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from app.celery.scheduled_tasks import (
|
|||||||
switch_current_sms_provider_on_slow_delivery,
|
switch_current_sms_provider_on_slow_delivery,
|
||||||
trigger_link_tests,
|
trigger_link_tests,
|
||||||
)
|
)
|
||||||
from app.config import Config, QueueNames
|
from app.config import Config, QueueNames, TaskNames
|
||||||
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.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 (
|
||||||
@@ -668,24 +668,35 @@ def test_trigger_link_does_nothing_if_cbc_proxy_disabled(
|
|||||||
|
|
||||||
|
|
||||||
@freeze_time('2021-07-19 15:50')
|
@freeze_time('2021-07-19 15:50')
|
||||||
@pytest.mark.parametrize('status, finishes_at, final_status', [
|
@pytest.mark.parametrize('status, finishes_at, final_status, should_call_publish_task', [
|
||||||
(BroadcastStatusType.BROADCASTING, '2021-07-19 16:00', BroadcastStatusType.BROADCASTING),
|
(BroadcastStatusType.BROADCASTING, '2021-07-19 16:00', BroadcastStatusType.BROADCASTING, False),
|
||||||
(BroadcastStatusType.BROADCASTING, '2021-07-19 15:40', BroadcastStatusType.COMPLETED),
|
(BroadcastStatusType.BROADCASTING, '2021-07-19 15:40', BroadcastStatusType.COMPLETED, True),
|
||||||
(BroadcastStatusType.BROADCASTING, None, BroadcastStatusType.BROADCASTING),
|
(BroadcastStatusType.BROADCASTING, None, BroadcastStatusType.BROADCASTING, False),
|
||||||
(BroadcastStatusType.PENDING_APPROVAL, None, BroadcastStatusType.PENDING_APPROVAL),
|
(BroadcastStatusType.PENDING_APPROVAL, None, BroadcastStatusType.PENDING_APPROVAL, False),
|
||||||
(BroadcastStatusType.CANCELLED, '2021-07-19 15:40', BroadcastStatusType.CANCELLED),
|
(BroadcastStatusType.CANCELLED, '2021-07-19 15:40', BroadcastStatusType.CANCELLED, False),
|
||||||
])
|
])
|
||||||
def test_auto_expire_broadcast_messages(
|
def test_auto_expire_broadcast_messages(
|
||||||
|
mocker,
|
||||||
status,
|
status,
|
||||||
finishes_at,
|
finishes_at,
|
||||||
final_status,
|
final_status,
|
||||||
sample_template
|
sample_template,
|
||||||
|
should_call_publish_task,
|
||||||
):
|
):
|
||||||
message = create_broadcast_message(
|
message = create_broadcast_message(
|
||||||
status=status,
|
status=status,
|
||||||
finishes_at=finishes_at,
|
finishes_at=finishes_at,
|
||||||
template=sample_template,
|
template=sample_template,
|
||||||
)
|
)
|
||||||
|
mock_celery = mocker.patch('app.celery.scheduled_tasks.notify_celery.send_task')
|
||||||
|
|
||||||
auto_expire_broadcast_messages()
|
auto_expire_broadcast_messages()
|
||||||
assert message.status == final_status
|
assert message.status == final_status
|
||||||
|
|
||||||
|
if should_call_publish_task:
|
||||||
|
mock_celery.assert_called_once_with(
|
||||||
|
name=TaskNames.PUBLISH_GOVUK_ALERTS,
|
||||||
|
queue=QueueNames.GOVUK_ALERTS
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
assert not mock_celery.called
|
||||||
|
|||||||
Reference in New Issue
Block a user