Skip to content

Commit

Permalink
Merge pull request #320 from coderxio/jrlegrand/max-workers
Browse files Browse the repository at this point in the history
Max workers 3
  • Loading branch information
jrlegrand authored Oct 4, 2024
2 parents c6a9e0c + 243f274 commit b589a88
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions airflow/dags/sagerx.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,16 @@ def get_api(url):
def parallel_api_calls(api_calls:list) -> list:
from concurrent.futures import ThreadPoolExecutor, as_completed
output = []
with ThreadPoolExecutor(max_workers=32) as executor:
with ThreadPoolExecutor(max_workers=3) as executor:
futures = {executor.submit(get_api, api_call):api_call for api_call in api_calls}

for future in as_completed(futures):
url = futures[future]
response = future.result()
if not len(response) == 0:
output.append({"url":url,"response":response})
else:
print(f"Empty response for url: {url}")
if len(output) % 1000 == 0:
print(f'MILESTONE {len(output)}')
# else:
# print(f"Empty response for url: {url}")
return output

0 comments on commit b589a88

Please sign in to comment.