58 lines
1.8 KiB
Python
Raw Normal View History

import logging
from celery.app import shared_task
from django.utils import timezone
2024-10-09 21:54:31 +02:00
from notfellchen.celery import app as celery_app
from .mail import send_notification_email
2024-11-06 23:32:37 +01:00
from .tools.admin import clean_locations, deactivate_unchecked_adoption_notices, deactivate_404_adoption_notices
2024-10-10 18:35:22 +02:00
from .tools.misc import healthcheck_ok
2024-10-19 19:45:42 +02:00
from .models import Location, AdoptionNotice, Timestamp
from .tools.search import notify_search_subscribers
2024-10-19 19:45:42 +02:00
def set_timestamp(key: str):
try:
ts = Timestamp.objects.get(key=key)
ts.timestamp = timezone.now()
2024-11-07 21:58:12 +01:00
ts.save()
2024-10-19 19:45:42 +02:00
except Timestamp.DoesNotExist:
Timestamp.objects.create(key=key, timestamp=timezone.now())
2024-10-10 07:39:44 +02:00
2024-10-09 21:54:31 +02:00
@celery_app.task(name="admin.clean_locations")
def task_clean_locations():
clean_locations()
2024-10-19 19:45:42 +02:00
set_timestamp("task_clean_locations")
2024-10-10 07:39:44 +02:00
2024-11-06 23:32:37 +01:00
@celery_app.task(name="admin.daily_unchecked_deactivation")
def task_deactivate_unchecked():
deactivate_unchecked_adoption_notices()
2024-11-06 23:32:37 +01:00
set_timestamp("task_daily_unchecked_deactivation")
@celery_app.task(name="admin.deactivate_404_adoption_notices")
def task_deactivate_unchecked():
deactivate_404_adoption_notices()
set_timestamp("task_deactivate_404_adoption_notices")
@celery_app.task(name="commit.post_an_save")
def post_adoption_notice_save(pk):
2024-10-10 07:39:44 +02:00
instance = AdoptionNotice.objects.get(pk=pk)
Location.add_location_to_object(instance)
2024-10-19 19:45:42 +02:00
set_timestamp("add_adoption_notice_location")
logging.info(f"Location was added to Adoption notice {pk}")
2024-10-19 19:45:42 +02:00
notify_search_subscribers(instance, only_if_active=True)
2024-10-10 18:35:22 +02:00
@celery_app.task(name="tools.healthcheck")
def task_healthcheck():
healthcheck_ok()
2024-10-19 19:45:42 +02:00
set_timestamp("task_healthcheck")
@shared_task
def task_send_notification_email(notification_pk):
send_notification_email(notification_pk)