DRF_Template/backend/search_results/tasks.py

15 lines
457 B
Python
Raw Normal View History

from celery import shared_task
2024-10-31 00:33:13 +08:00
from .models import SearchResult
@shared_task(
autoretry_for=(Exception,), retry_kwargs={"max_retries": 0, "countdown": 5}
)
def create_search_result(title, link):
if SearchResult.objects.filter(title=title, link=link).exists():
return "SearchResult entry already exists"
else:
SearchResult.objects.create(title=title, link=link)
return f"Created new SearchResult entry titled: {title}"