From e25ace802e6253e27c897d1f62125b56cb795d76 Mon Sep 17 00:00:00 2001 From: Bryce Date: Fri, 7 Nov 2025 15:06:25 -0800 Subject: [PATCH] multi --- app.py | 2 +- worker_pool.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index bb86e60..6977031 100644 --- a/app.py +++ b/app.py @@ -297,7 +297,7 @@ def fetch_all_projects(): import worker_pool - detailed_rows = worker_pool.process_projects_parallel(projects, bearer, 5) + detailed_rows = worker_pool.process_projects_parallel(projects, bearer, 9) # Store the results in Firestore projects_ref = db.collection("projects") # Clear existing projects diff --git a/worker_pool.py b/worker_pool.py index 5936ab0..5e086e1 100644 --- a/worker_pool.py +++ b/worker_pool.py @@ -18,7 +18,7 @@ def worker_init(bearer_token: str): """Initialize worker with bearer token""" set_bearer_token(bearer_token) -def process_project(project_data: dict, bearer_token: str) -> dict: +def process_project(index: int, total: int, project_data: dict, bearer_token: str) -> dict: """ Process a single project with all its API calls. This is the function that will be executed by workers in parallel. @@ -39,7 +39,7 @@ def process_project(project_data: dict, bearer_token: str) -> dict: p = project_data pid = (p.get("projectId") or {}).get("native") - print(f"Working on {pid}") + print(f"Working on {pid} ({index}/{total})") c = fetch_client(bearer_token, (p.get("clientId") or {}).get("native")) cs = fetch_contacts(bearer_token, pid) @@ -197,7 +197,7 @@ def process_project(project_data: dict, bearer_token: str) -> dict: "ProjectName": p.get("projectName") or detail.get("projectName"), "ProjectUrl": p.get("projectUrl") or detail.get("projectUrl"), } - print(f"finished {pid}") + print(f"Finished on {pid} ({index}/{total})") return row @@ -214,9 +214,10 @@ def process_projects_parallel(projects: List[dict], bearer_token: str, max_worke List of processed project dictionaries """ # Create a thread pool with specified number of workers + total = len(projects) with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers, initializer=worker_init, initargs=(bearer_token,)) as executor: # Submit all tasks to the executor - future_to_project = {executor.submit(process_project, project, bearer_token): project for project in projects} + future_to_project = {executor.submit(process_project, indx, total, project, bearer_token): project for indx, project in enumerate(projects)} # Collect results as they complete results = []