from django_rq import job from .src.fetch_feed import FetchFeeds from .src.fetch_parser import FetchParser from .src.fetch_search import FetchSearcher from .src.db_utils import DB_Handler ''' from src.fetch_search import FetchSearcher from src.missing_kids_fetch import MissingKidsFetch from src.missing_kids_status import MissingKidsStatus ''' from .src.logger import get_logger logger = get_logger() @job def background_task(process_type: str): logger.info("Task triggered: {}".format(process_type)) try: if (process_type == "fetch_feeds"): FetchFeeds().run() elif (process_type == "fetch_parser"): FetchParser().run() elif (process_type == "fetch_search"): FetchSearcher().run() #elif (process_type == "fetch_missingkids"): # FetchMissingKids().run() elif ("process_" in process_type): # Batch size encoded in URL batch_size = int(process_type.split("_")[-1]) # Task type if ("process_raw_urls" in process_type): DB_Handler().process_raw_urls(batch_size=batch_size) elif ("process_error_urls" in process_type): DB_Handler().process_error_urls(batch_size=batch_size) elif ("process_missing_kids_urls" in process_type): DB_Handler().process_missing_kids_urls(batch_size=batch_size) else: logger.info("Task unknown!: {}".format(process_type)) ''' elif (process_type == "search") or (process_type == "search_full"): FetchSearcher(cred.db_connect_info, cred.redis_connect_info, full=True).run() elif (process_type == "search_reduced"): FetchSearcher(cred.db_connect_info, cred.redis_connect_info, full=False).run() # Selenium based elif (process_type == "fetch_missing_kids_reduced"): MissingKidsFetch(db_handler, num_pages=4).run() elif (process_type == "fetch_missing_kids_full"): MissingKidsFetch(db_handler, num_pages=100000).run() else: logger.error("Task error, unknown type: {}".format(process_type)) return ''' logger.info("Task completed: {}".format(process_type)) except Exception as e: logger.error(e)