Browse Source

feat(crawler): support forced execution for manual crawl runs

master
PouyaKhajavi 1 day ago
parent
commit
381147689f
  1. 17
      backend/crawler/tasks.py
  2. 2
      backend/crawler/views.py

17
backend/crawler/tasks.py

@ -91,7 +91,7 @@ def extract_widgets_from_dict(d, found_ads):
extract_widgets_from_dict(item, found_ads)
@shared_task
def run_crawl_pipeline(run_id):
def run_crawl_pipeline(run_id, force=False):
"""
Background Celery task that executes a crawling run.
Parses Divar listing data, registers new Ads, and queues AI evaluations.
@ -111,13 +111,14 @@ def run_crawl_pipeline(run_id):
run.save()
return
now = timezone.localtime(timezone.now()).time()
if not (task.start_hour <= now <= task.end_hour):
run.status = 'SUCCESS'
run.finished_at = timezone.now()
run.error_log = f"Skipped: current time {now.strftime('%H:%M')} is outside allowed window {task.start_hour.strftime('%H:%M')} to {task.end_hour.strftime('%H:%M')}"
run.save()
return
if not force:
now = timezone.localtime(timezone.now()).time()
if not (task.start_hour <= now <= task.end_hour):
run.status = 'SUCCESS'
run.finished_at = timezone.now()
run.error_log = f"Skipped: current time {now.strftime('%H:%M')} is outside allowed window {task.start_hour.strftime('%H:%M')} to {task.end_hour.strftime('%H:%M')}"
run.save()
return
# Update run status to RUNNING
run.status = 'RUNNING'

2
backend/crawler/views.py

@ -25,7 +25,7 @@ class CrawlTaskViewSet(viewsets.ModelViewSet):
try:
from crawler.tasks import run_crawl_pipeline
# run asynchronously
run_crawl_pipeline.delay(str(run.id))
run_crawl_pipeline.delay(str(run.id), force=True)
is_queued = True
except ImportError:
# Fallback if tasks.py doesn't exist yet or run_crawl_pipeline is not defined

Loading…
Cancel
Save