diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index aaaa330..8f2e62f 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -655,4 +655,16 @@ class Log(models.Model): created_at = models.DateTimeField(auto_now_add=True) def __str__(self): - return f"[{self.action}] - {self.user} - {self.created_at.strftime('%H:%M:%S %d-%m-%Y ')}" \ No newline at end of file + return f"[{self.action}] - {self.user} - {self.created_at.strftime('%H:%M:%S %d-%m-%Y ')}" + + +class Timestamp(models.Model): + """ + Class to store timestamps based on keys + """ + key = models.CharField(max_length=255, verbose_name=_("Schlüssel"), primary_key=True) + timestamp = models.DateTimeField(auto_now_add=True, verbose_name=_("Zeitstempel")) + data = models.CharField(max_length=2000, blank=True, null=True) + + def ___str__(self): + return f"[{self.key}] - {self.timestamp.strftime('%H:%M:%S %d-%m-%Y ')} - {self.data}" diff --git a/src/fellchensammlung/tasks.py b/src/fellchensammlung/tasks.py index 418e9c0..2731609 100644 --- a/src/fellchensammlung/tasks.py +++ b/src/fellchensammlung/tasks.py @@ -1,24 +1,38 @@ +from datetime import datetime from notfellchen.celery import app as celery_app 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, Timestamp + + +def set_timestamp(key: str): + try: + ts = Timestamp.objects.get(key=key) + ts.timestamp = datetime.now() + except Timestamp.DoesNotExist: + Timestamp.objects.create(key=key, timestamp=datetime.now()) @celery_app.task(name="admin.clean_locations") def task_clean_locations(): clean_locations() + set_timestamp("task_clean_locations") @celery_app.task(name="admin.deactivate_unchecked") def task_deactivate_unchecked(): deactivate_unchecked_adoption_notices() + set_timestamp("task_deactivate_unchecked") @celery_app.task(name="commit.add_location") def add_adoption_notice_location(pk): instance = AdoptionNotice.objects.get(pk=pk) Location.add_location_to_object(instance) + set_timestamp("add_adoption_notice_location") + @celery_app.task(name="tools.healthcheck") def task_healthcheck(): healthcheck_ok() + set_timestamp("task_healthcheck")