Fixes after first test

This commit is contained in:
2026-03-28 02:29:24 +01:00
parent 61ce661332
commit a2dea95c89
8 changed files with 44046 additions and 49 deletions

Binary file not shown.

View File

@@ -1169,10 +1169,6 @@ def _process_single_request(worklist_request, mapping_dict):
else: else:
request_detail["Center_Name"] = None request_detail["Center_Name"] = None
# Also inject organization and labeledOrganization for mapping access
request_detail["organization"] = worklist_request.get("organization")
request_detail["labeledOrganization"] = labeled_org
# --- 6. Apply requests mapping to produce output object --- # --- 6. Apply requests mapping to produce output object ---
output_request = {} output_request = {}
process_requests_mapping(output_request, request_detail) process_requests_mapping(output_request, request_detail)
@@ -1324,10 +1320,12 @@ def main():
print() print()
console.print("[bold cyan]Loading Excel export configuration...[/bold cyan]") console.print("[bold cyan]Loading Excel export configuration...[/bold cyan]")
excel_export_config, has_config_critical, _ = \ excel_export_config, has_config_critical, config_error_messages = \
prepare_excel_export(requests_mapping_config, organizations_mapping_config) prepare_excel_export(requests_mapping_config, organizations_mapping_config)
if has_config_critical: if has_config_critical:
for err in config_error_messages:
console.print(f"[bold red] • {err}[/bold red]")
print() print()
answer = questionary.confirm( answer = questionary.confirm(
"⚠ Critical configuration errors detected. Continue anyway?", "⚠ Critical configuration errors detected. Continue anyway?",
@@ -1361,61 +1359,87 @@ def main():
print() print()
# === SUBMIT ALL REQUESTS TO THREAD POOL AS PAGES ARRIVE === # === SUBMIT ALL REQUESTS TO THREAD POOL AS PAGES ARRIVE ===
# Both progress bars are shown simultaneously:
# - fetching_pbar (position=0): advances by the number of requests in each fetched page
# - processing_pbar (position=1): advances as each request finishes processing
# Completed futures are drained inline after each page so the processing bar
# starts moving immediately, without waiting for all pages to be fetched first.
all_futures = [] all_futures = []
all_results = []
completed_set = set()
with ThreadPoolExecutor(max_workers=number_of_threads) as thread_pool: with ThreadPoolExecutor(max_workers=number_of_threads) as thread_pool:
# Progress bar 1: page fetching with tqdm(total=total_requests, unit="req.",
with tqdm(total=total_pages, unit="page", desc=f"{'Fetching requests':<52}",
desc=f"{'Fetching pages':<52}",
position=0, leave=True, position=0, leave=True,
bar_format=custom_bar_format) as pages_pbar: bar_format=custom_bar_format) as fetching_pbar:
# Submit first page requests with tqdm(total=total_requests, unit="req.",
for worklist_request in first_page.get("data", []): desc=f"{'Processing requests':<52}",
f = thread_pool.submit(run_with_context, _process_single_request, position=1, leave=True,
{"id": worklist_request.get("id")}, bar_format=custom_bar_format) as processing_pbar:
worklist_request, mapping_dict)
all_futures.append(f)
pages_pbar.update(1)
# Fetch and submit remaining pages global_pbar = processing_pbar
for page_num in range(2, total_pages + 1):
page_data = get_worklist_page(do_filters, page_num, DO_WORKLIST_PAGE_SIZE) def _drain_completed():
for worklist_request in page_data.get("data", []): for f in list(all_futures):
if f not in completed_set and f.done():
try:
result = f.result()
all_results.append(result)
except Exception as exc:
logging.critical(f"Critical exception in request worker: {exc}", exc_info=True)
print(f"\nCRITICAL ERROR in request processing thread:")
print(f"Exception: {exc}")
traceback.print_exc()
thread_pool.shutdown(wait=False, cancel_futures=True)
raise
finally:
completed_set.add(f)
with _global_pbar_lock:
if global_pbar:
global_pbar.update(1)
# Submit first page requests
first_page_data = first_page.get("data", [])
for worklist_request in first_page_data:
f = thread_pool.submit(run_with_context, _process_single_request, f = thread_pool.submit(run_with_context, _process_single_request,
{"id": worklist_request.get("id")}, {"id": worklist_request.get("id")},
worklist_request, mapping_dict) worklist_request, mapping_dict)
all_futures.append(f) all_futures.append(f)
pages_pbar.update(1) fetching_pbar.update(len(first_page_data))
print() # Fetch and submit remaining pages; drain completed futures after each page
for page_num in range(2, total_pages + 1):
page_data = get_worklist_page(do_filters, page_num, DO_WORKLIST_PAGE_SIZE)
page_requests = page_data.get("data", [])
for worklist_request in page_requests:
f = thread_pool.submit(run_with_context, _process_single_request,
{"id": worklist_request.get("id")},
worklist_request, mapping_dict)
all_futures.append(f)
fetching_pbar.update(len(page_requests))
_drain_completed()
# Progress bar 2: request processing # Drain remaining futures not yet collected
all_results = [] # list of (output_request, request_meta) remaining = [f for f in all_futures if f not in completed_set]
for future in as_completed(remaining):
with tqdm(total=total_requests, unit="req.", try:
desc=f"{'Processing requests':<52}", result = future.result()
position=0, leave=True, all_results.append(result)
bar_format=custom_bar_format) as processing_pbar: except Exception as exc:
logging.critical(f"Critical exception in request worker: {exc}", exc_info=True)
global_pbar = processing_pbar print(f"\nCRITICAL ERROR in request processing thread:")
print(f"Exception: {exc}")
for future in as_completed(all_futures): traceback.print_exc()
try: thread_pool.shutdown(wait=False, cancel_futures=True)
result = future.result() raise
all_results.append(result) finally:
except Exception as exc: completed_set.add(future)
logging.critical(f"Critical exception in request worker: {exc}", exc_info=True) with _global_pbar_lock:
print(f"\nCRITICAL ERROR in request processing thread:") if global_pbar:
print(f"Exception: {exc}") global_pbar.update(1)
traceback.print_exc()
thread_pool.shutdown(wait=False, cancel_futures=True)
raise
finally:
with _global_pbar_lock:
if global_pbar:
global_pbar.update(1)
# === SORT RESULTS === # === SORT RESULTS ===
print() print()

View File

@@ -62,8 +62,8 @@ IAM_URL = "https://api-auth.ziwig-connect.com"
GDD_URL = "https://api-lab.ziwig-connect.com" GDD_URL = "https://api-lab.ziwig-connect.com"
GDD_APP_ID = "4f5ac063-6a22-4e2c-bda5-b50c0dddab79" GDD_APP_ID = "4f5ac063-6a22-4e2c-bda5-b50c0dddab79"
DEFAULT_USER_NAME = "ziwig-invest2@yopmail.com" DEFAULT_USER_NAME = "paul.renaud"
DEFAULT_PASSWORD = "pbrrA765$bP3beiuyuiyhiuy!agxagx" DEFAULT_PASSWORD = "Abdel#@#@#@123"
# ============================================================================ # ============================================================================
# API ENDPOINTS # API ENDPOINTS

1122
do_organizations.json Normal file

File diff suppressed because it is too large Load Diff

42851
do_requests.json Normal file

File diff suppressed because it is too large Load Diff