Notfellchen/src/fellchensammlung/tasks.py

39 lines
1.1 KiB
Python
Raw Normal View History

2024-10-19 17:45:42 +00:00
from datetime import datetime
2024-10-09 19:54:31 +00:00
from notfellchen.celery import app as celery_app
from .tools.admin import clean_locations, deactivate_unchecked_adoption_notices
2024-10-10 16:35:22 +00:00
from .tools.misc import healthcheck_ok
2024-10-19 17:45:42 +00:00
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())
2024-10-10 05:39:44 +00:00
2024-10-09 19:54:31 +00:00
@celery_app.task(name="admin.clean_locations")
def task_clean_locations():
clean_locations()
2024-10-19 17:45:42 +00:00
set_timestamp("task_clean_locations")
2024-10-10 05:39:44 +00:00
@celery_app.task(name="admin.deactivate_unchecked")
def task_deactivate_unchecked():
deactivate_unchecked_adoption_notices()
2024-10-19 17:45:42 +00:00
set_timestamp("task_deactivate_unchecked")
2024-10-10 05:39:44 +00:00
@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)
2024-10-19 17:45:42 +00:00
set_timestamp("add_adoption_notice_location")
2024-10-10 16:35:22 +00:00
@celery_app.task(name="tools.healthcheck")
def task_healthcheck():
healthcheck_ok()
2024-10-19 17:45:42 +00:00
set_timestamp("task_healthcheck")