2025-01-01 00:30:14 +01:00
|
|
|
import logging
|
|
|
|
|
2024-11-20 20:26:44 +01:00
|
|
|
from celery.app import shared_task
|
2024-10-29 17:50:29 +01:00
|
|
|
from django.utils import timezone
|
2024-10-09 21:54:31 +02:00
|
|
|
from notfellchen.celery import app as celery_app
|
2024-11-20 20:26:44 +01:00
|
|
|
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
|
2025-01-01 00:30:14 +01:00
|
|
|
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)
|
2024-10-29 17:50:29 +01:00
|
|
|
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:
|
2024-10-29 17:50:29 +01:00
|
|
|
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")
|
2024-10-10 17:07:11 +02:00
|
|
|
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")
|
2024-10-10 17:07:11 +02:00
|
|
|
|
|
|
|
|
2025-01-01 14:35:40 +01:00
|
|
|
@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")
|
2025-01-01 14:35:40 +01:00
|
|
|
logging.info(f"Location was added to Adoption notice {pk}")
|
2024-10-19 19:45:42 +02:00
|
|
|
|
2025-01-01 14:35:40 +01: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")
|
2024-11-20 20:26:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
|
|
|
def task_send_notification_email(notification_pk):
|
|
|
|
send_notification_email(notification_pk)
|