-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from uktrade/update-healthcheck-separate-p1-p2
Update healthcheck separate p1 p2
- Loading branch information
Showing
10 changed files
with
199 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class HealthcheckConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "healthcheck" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import datetime | ||
import logging | ||
import poplib | ||
|
||
from background_task.models import Task | ||
from django.conf import settings | ||
from django.utils import timezone | ||
|
||
from mail.enums import ReceptionStatusEnum | ||
from mail.libraries.routing_controller import get_hmrc_to_dit_mailserver, get_spire_to_dit_mailserver | ||
from mail.models import LicencePayload, Mail | ||
from mail.tasks import LICENCE_DATA_TASK_QUEUE, MANAGE_INBOX_TASK_QUEUE | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def can_authenticate_mailboxes(): | ||
mailserver_factories = ( | ||
get_hmrc_to_dit_mailserver, | ||
get_spire_to_dit_mailserver, | ||
) | ||
mailbox_results = [] | ||
for mailserver_factory in mailserver_factories: | ||
mailserver = mailserver_factory() | ||
try: | ||
mailserver.connect_to_pop3() | ||
except poplib.error_proto as e: | ||
response, *_ = e.args | ||
logger.error( | ||
"Failed to connect to mailbox: %s (%s)", | ||
mailserver.hostname, | ||
response, | ||
) | ||
mailbox_results.append(False) | ||
else: | ||
mailbox_results.append(True) | ||
finally: | ||
mailserver.quit_pop3_connection() | ||
|
||
return all(mailbox_results) | ||
|
||
|
||
def is_licence_payloads_processing(): | ||
dt = timezone.now() + datetime.timedelta(seconds=settings.LICENSE_POLL_INTERVAL) | ||
|
||
unprocessed_payloads = LicencePayload.objects.filter(is_processed=False, received_at__lte=dt) | ||
for unprocessed_payload in unprocessed_payloads: | ||
logger.error( | ||
"Payload object has been unprocessed for over %s seconds: %s", | ||
settings.LICENSE_POLL_INTERVAL, | ||
unprocessed_payload, | ||
) | ||
|
||
return not unprocessed_payloads.exists() | ||
|
||
|
||
def is_lite_licence_update_task_responsive(): | ||
dt = timezone.now() + datetime.timedelta(seconds=settings.LITE_LICENCE_DATA_POLL_INTERVAL) | ||
|
||
return Task.objects.filter(queue=LICENCE_DATA_TASK_QUEUE, run_at__lte=dt).exists() | ||
|
||
|
||
def is_manage_inbox_task_responsive(): | ||
dt = timezone.now() + datetime.timedelta(seconds=settings.INBOX_POLL_INTERVAL) | ||
|
||
return Task.objects.filter(queue=MANAGE_INBOX_TASK_QUEUE, run_at__lte=dt).exists() | ||
|
||
|
||
def is_pending_mail_processing(): | ||
dt = timezone.now() - datetime.timedelta(seconds=settings.EMAIL_AWAITING_REPLY_TIME) | ||
|
||
pending_mails = Mail.objects.exclude(status=ReceptionStatusEnum.REPLY_SENT).filter(sent_at__lte=dt) | ||
for pending_mail in pending_mails: | ||
logger.error( | ||
"The following Mail has been pending for over %s seconds: %s", | ||
settings.EMAIL_AWAITING_REPLY_TIME, | ||
pending_mail, | ||
) | ||
|
||
return not pending_mails.exists() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
path("", views.HealthCheckP1.as_view(), name="healthcheck_p1"), | ||
path("p2/", views.HealthCheckP2.as_view(), name="healthcheck_p2"), | ||
] |
Oops, something went wrong.