mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Add task to send canary to cbc proxy
Create and schedule a Celery task that tests if we can send a canary message to cbc proxy. This will help us know if something happens to our connection to cbc proxy. Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk> Co-authored-by: Pea <pea.tyczynska@digital.cabinet-office.gov.uk> Co-authored-by: Richard <richard.baker@digital.cabinet-office.gov.uk>
This commit is contained in:
committed by
Pea Tyczynska
parent
052de84c9e
commit
be90455944
@@ -1,3 +1,5 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
from datetime import (
|
from datetime import (
|
||||||
datetime,
|
datetime,
|
||||||
timedelta
|
timedelta
|
||||||
@@ -8,7 +10,7 @@ from notifications_utils.statsd_decorators import statsd
|
|||||||
from sqlalchemy import and_
|
from sqlalchemy import and_
|
||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
|
|
||||||
from app import notify_celery, zendesk_client
|
from app import cbc_proxy_client, notify_celery, zendesk_client
|
||||||
from app.celery.tasks import (
|
from app.celery.tasks import (
|
||||||
process_job,
|
process_job,
|
||||||
get_recipient_csv_and_template_and_sender_id,
|
get_recipient_csv_and_template_and_sender_id,
|
||||||
@@ -291,3 +293,9 @@ def check_for_services_with_high_failure_rates_or_sending_to_tv_numbers():
|
|||||||
message=message,
|
message=message,
|
||||||
ticket_type=zendesk_client.TYPE_INCIDENT
|
ticket_type=zendesk_client.TYPE_INCIDENT
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@notify_celery.task(name='send-canary-to-cbc-proxy')
|
||||||
|
def send_canary_to_cbc_proxy():
|
||||||
|
identifier = str(uuid.uuid4())
|
||||||
|
cbc_proxy_client.send_canary(identifier)
|
||||||
|
|||||||
@@ -303,6 +303,11 @@ class Config(object):
|
|||||||
'schedule': crontab(hour=23, minute=00),
|
'schedule': crontab(hour=23, minute=00),
|
||||||
'options': {'queue': QueueNames.PERIODIC}
|
'options': {'queue': QueueNames.PERIODIC}
|
||||||
},
|
},
|
||||||
|
'send-canary-to-cbc-proxy': {
|
||||||
|
'task': 'send-canary-to-cbc-proxy',
|
||||||
|
'schedule': timedelta(minutes=5),
|
||||||
|
'options': {'queue': QueueNames.PERIODIC}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
CELERY_QUEUES = []
|
CELERY_QUEUES = []
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import uuid
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from unittest.mock import call
|
from unittest.mock import call
|
||||||
|
|
||||||
@@ -555,3 +556,22 @@ def test_check_for_services_with_high_failure_rates_or_sending_to_tv_numbers(
|
|||||||
subject="[test] High failure rates for sms spotted for services",
|
subject="[test] High failure rates for sms spotted for services",
|
||||||
ticket_type='incident'
|
ticket_type='incident'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_send_canary_to_cbc_proxy_invokes_cbc_proxy_client(
|
||||||
|
mocker,
|
||||||
|
):
|
||||||
|
mock_send_canary = mocker.patch(
|
||||||
|
'app.cbc_proxy_client.send_canary',
|
||||||
|
)
|
||||||
|
|
||||||
|
scheduled_tasks.send_canary_to_cbc_proxy()
|
||||||
|
|
||||||
|
mock_send_canary.assert_called
|
||||||
|
# the 0th argument of the call to send_canary
|
||||||
|
identifier = mock_send_canary.mock_calls[0][1][0]
|
||||||
|
|
||||||
|
try:
|
||||||
|
uuid.UUID(identifier)
|
||||||
|
except BaseException:
|
||||||
|
pytest.fail(f"{identifier} is not a valid uuid")
|
||||||
|
|||||||
Reference in New Issue
Block a user