feat: Add healthcheck
This commit is contained in:
parent
e38234b736
commit
74a6b5f2aa
@ -1,5 +1,6 @@
|
|||||||
from notfellchen.celery import app as celery_app
|
from notfellchen.celery import app as celery_app
|
||||||
from .tools.admin import clean_locations, deactivate_unchecked_adoption_notices
|
from .tools.admin import clean_locations, deactivate_unchecked_adoption_notices
|
||||||
|
from .tools.misc import healthcheck_ok
|
||||||
from .models import Location, AdoptionNotice
|
from .models import Location, AdoptionNotice
|
||||||
|
|
||||||
|
|
||||||
@ -17,3 +18,7 @@ def task_deactivate_unchecked():
|
|||||||
def add_adoption_notice_location(pk):
|
def add_adoption_notice_location(pk):
|
||||||
instance = AdoptionNotice.objects.get(pk=pk)
|
instance = AdoptionNotice.objects.get(pk=pk)
|
||||||
Location.add_location_to_object(instance)
|
Location.add_location_to_object(instance)
|
||||||
|
|
||||||
|
@celery_app.task(name="tools.healthcheck")
|
||||||
|
def task_healthcheck():
|
||||||
|
healthcheck_ok()
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
import datetime as datetime
|
import datetime as datetime
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from notfellchen import settings
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
def pluralize(number, letter="e"):
|
def pluralize(number, letter="e"):
|
||||||
@ -23,3 +27,10 @@ def age_as_hr_string(age: datetime.timedelta) -> str:
|
|||||||
return f'{weeks:.0f} Woche{pluralize(weeks, "n")}'
|
return f'{weeks:.0f} Woche{pluralize(weeks, "n")}'
|
||||||
else:
|
else:
|
||||||
return f'{days:.0f} Tag{pluralize(days)}'
|
return f'{days:.0f} Tag{pluralize(days)}'
|
||||||
|
|
||||||
|
|
||||||
|
def healthcheck_ok():
|
||||||
|
try:
|
||||||
|
requests.get(settings.HEALTHCHECK_URL, timeout=10)
|
||||||
|
except requests.RequestException as e:
|
||||||
|
logging.error("Ping to healthcheck-server failed: %s" % e)
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
# <your_project>/celery.py
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from celery import Celery
|
from celery import Celery
|
||||||
from celery.schedules import crontab
|
from celery.schedules import crontab
|
||||||
|
from notfellchen import settings
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'notfellchen.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'notfellchen.settings')
|
||||||
|
|
||||||
@ -19,7 +18,12 @@ app.conf.beat_schedule = {
|
|||||||
},
|
},
|
||||||
'daily-deactivation': {
|
'daily-deactivation': {
|
||||||
'task': 'admin.deactivate_unchecked',
|
'task': 'admin.deactivate_unchecked',
|
||||||
'schedule': 30,
|
'schedule': crontab(hour=1),
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if settings.HEALTHCHECK_URL is not None:
|
||||||
|
# If a healthcheck is configured, this will send a daily ping to the healthchecks server
|
||||||
|
app.conf.beat_schedule['daily-healthcheck'] = {'task': 'tools.healthcheck',
|
||||||
|
'schedule': crontab(hour=2),
|
||||||
|
}
|
||||||
|
@ -84,6 +84,8 @@ LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]
|
|||||||
CELERY_BROKER_URL = config.get("celery", "broker", fallback="redis://localhost:6379/0")
|
CELERY_BROKER_URL = config.get("celery", "broker", fallback="redis://localhost:6379/0")
|
||||||
CELERY_RESULT_BACKEND = config.get("celery", "backend", fallback="redis://localhost:6379/0")
|
CELERY_RESULT_BACKEND = config.get("celery", "backend", fallback="redis://localhost:6379/0")
|
||||||
|
|
||||||
|
""" MONITORING """
|
||||||
|
HEALTHCHECKS_URL = config.get("monitoring", "healthchecks_url", fallback=None)
|
||||||
|
|
||||||
""" GEOCODING """
|
""" GEOCODING """
|
||||||
GEOCODING_API_URL = config.get("geocoding", "api_url", fallback="https://nominatim.hyteck.de/search")
|
GEOCODING_API_URL = config.get("geocoding", "api_url", fallback="https://nominatim.hyteck.de/search")
|
||||||
|
Loading…
Reference in New Issue
Block a user