Skip to content

Commit

Permalink
refactor health check
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrindt committed Sep 13, 2023
1 parent b861866 commit 2fe7d72
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 154 deletions.
148 changes: 8 additions & 140 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,144 +1,12 @@
# not execution related files
# not docker execution related files
.github
.pytest_cache
data
docs
tests

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so


# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# build artifacts
docs/api/ephios-open-api-schema.yml

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
data

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
dist
build
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
.idea
.env.example

# IDEA files
.idea/
2 changes: 1 addition & 1 deletion deployment/docker/cron.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

while [ true ]; do
sleep 60
echo "Running cron job"
/usr/local/bin/python3 -m ephios run_periodic
sleep 60
done
6 changes: 3 additions & 3 deletions ephios/core/services/health/healthchecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def check(self):

if settings.DATABASES["default"]["ENGINE"] == "django.db.backends.sqlite3":
return HealthCheckStatus.WARNING, _(
"Using SQLite, this is not recommended in production."
"Using SQLite, which should not be used in production."
)

return HealthCheckStatus.OK, _("Database connection established.")
Expand All @@ -109,7 +109,7 @@ def check(self):
== "django.core.cache.backends.locmem.LocMemCache"
):
return HealthCheckStatus.WARNING, _(
"Using LocMemCache, this is not recommended in production."
"Using LocMemCache, which should not be used in production."
)

return HealthCheckStatus.OK, _("Cache connection established.")
Expand Down Expand Up @@ -166,7 +166,7 @@ def check(self):
)
return (
HealthCheckStatus.OK,
mark_safe(_("Media root writable by application server.")),
mark_safe(_("Media root is writable by application server.")),
)


Expand Down
22 changes: 12 additions & 10 deletions ephios/core/views/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@

class HealthCheckView(View):
def get(self, request, *args, **kwargs):
messages = []
errors = []
okays = []
not_okays = []

for check, status, message in run_healthchecks():
text = f"{check.name}: {message}"
if status == HealthCheckStatus.OK:
messages.append(text)
okays.append(text)
else:
errors.append(text)
not_okays.append(text)

if errors:
return HttpResponse(
"<br/>".join(errors) + "<br/><br/>" + "<br/>".join(messages), status=503
)

return HttpResponse("<br/>".join(messages), status=200)
status = 200
message = ""
if not_okays:
status = 503
message += "NOT OK<br/><br/>" + "<br/>".join(not_okays) + "<br/><br/>"
if okays:
message += "OK<br/><br/>" + "<br/>".join(okays) + "<br/><br/>"
return HttpResponse(message, status=status)

0 comments on commit 2fe7d72

Please sign in to comment.