mirror of
https://github.com/lemeow125/DRF_Template.git
synced 2025-08-03 01:33:15 +08:00
Update webdriver utility functions and add a sample celery task for scraping Google search
This commit is contained in:
parent
0e902b1f04
commit
9e2e32fba8
11 changed files with 193 additions and 25 deletions
16
backend/search_results/tasks.py
Normal file
16
backend/search_results/tasks.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
|
||||
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}"
|
Loading…
Add table
Add a link
Reference in a new issue