diff --git a/backend/crawler/tasks.py b/backend/crawler/tasks.py index 10c57b2..bfe6c2e 100644 --- a/backend/crawler/tasks.py +++ b/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' diff --git a/backend/crawler/views.py b/backend/crawler/views.py index c308596..323c6bf 100644 --- a/backend/crawler/views.py +++ b/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