DRF_Template/backend/search_results/tasks.py

16 lines
488 B
Python

from celery import shared_task
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}"