feat: Log tasks
This commit is contained in:
parent
975de1a230
commit
1282b6b201
@ -656,3 +656,15 @@ class Log(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"[{self.action}] - {self.user} - {self.created_at.strftime('%H:%M:%S %d-%m-%Y ')}"
|
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}"
|
||||||
|
@ -1,24 +1,38 @@
|
|||||||
|
from datetime import datetime
|
||||||
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 .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")
|
@celery_app.task(name="admin.clean_locations")
|
||||||
def task_clean_locations():
|
def task_clean_locations():
|
||||||
clean_locations()
|
clean_locations()
|
||||||
|
set_timestamp("task_clean_locations")
|
||||||
|
|
||||||
|
|
||||||
@celery_app.task(name="admin.deactivate_unchecked")
|
@celery_app.task(name="admin.deactivate_unchecked")
|
||||||
def task_deactivate_unchecked():
|
def task_deactivate_unchecked():
|
||||||
deactivate_unchecked_adoption_notices()
|
deactivate_unchecked_adoption_notices()
|
||||||
|
set_timestamp("task_deactivate_unchecked")
|
||||||
|
|
||||||
|
|
||||||
@celery_app.task(name="commit.add_location")
|
@celery_app.task(name="commit.add_location")
|
||||||
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)
|
||||||
|
set_timestamp("add_adoption_notice_location")
|
||||||
|
|
||||||
|
|
||||||
@celery_app.task(name="tools.healthcheck")
|
@celery_app.task(name="tools.healthcheck")
|
||||||
def task_healthcheck():
|
def task_healthcheck():
|
||||||
healthcheck_ok()
|
healthcheck_ok()
|
||||||
|
set_timestamp("task_healthcheck")
|
||||||
|
Loading…
Reference in New Issue
Block a user