Skip to content

Commit

Permalink
chore: coding style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
terovirtanen committed Oct 1, 2024
1 parent ca76122 commit be02260
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion atv/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.1"
__version__ = "1.0.1"
2 changes: 1 addition & 1 deletion atv/settings.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import subprocess
from datetime import datetime

import environ
import sentry_sdk
from corsheaders.defaults import default_headers
from datetime import datetime
from django.core.exceptions import ImproperlyConfigured
from sentry_sdk.integrations.django import DjangoIntegration

Expand Down
26 changes: 18 additions & 8 deletions atv/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pyclamd
import threading
import time
from atv import __version__

import pyclamd
from django.conf import settings
from django.contrib import admin
from django.db import connection
Expand All @@ -14,6 +14,7 @@
)
from rest_framework_extensions.routers import ExtendedSimpleRouter

from atv import __version__
from documents.api import AttachmentViewSet, DocumentViewSet
from documents.api.viewsets import (
DocumentMetadataViewSet,
Expand Down Expand Up @@ -76,9 +77,10 @@
# Global variable to store the health check results
health_status = {
"db": {"message": "Initializing"},
"clamav": {"message": "Initializing"}
"clamav": {"message": "Initializing"},
}


def check_db_connection():
global health_status
while True:
Expand All @@ -90,6 +92,7 @@ def check_db_connection():
health_status["db"] = {"error": str(ex)}
time.sleep(300) # Sleep for 5 minutes


def check_clamav_connection():
global health_status
while True:
Expand All @@ -101,19 +104,18 @@ def check_clamav_connection():
health_status["clamav"] = {"error": str(ex)}
time.sleep(300) # Sleep for 5 minutes


# Start the health check threads
threading.Thread(target=check_db_connection, daemon=True).start()
threading.Thread(target=check_clamav_connection, daemon=True).start()


def healthz(*args, **kwargs):
response_data = {
"packageVersion": __version__,
"commitHash": settings.BUILD_COMMIT,
"buildTime": settings.APP_BUILDTIME,
"status": {
"message": {},
"error": {}
}
"status": {"message": {}, "error": {}},
}

for key, status in health_status.items():
Expand All @@ -122,9 +124,17 @@ def healthz(*args, **kwargs):
else:
response_data["status"]["error"][key] = status.get("error", "Unknown error")

status_code = 200 if all("message" in status and status["message"] == "OK" for status in health_status.values()) else 250
status_code = (
200
if all(
"message" in status and status["message"] == "OK"
for status in health_status.values()
)
else 200
)
return JsonResponse(response_data, status=status_code)


def readiness(*args, **kwargs):
return HttpResponse(status=200)

Expand Down

0 comments on commit be02260

Please sign in to comment.