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