Skip to content

Commit

Permalink
Httphook: rertry on ProxyError
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnestaP committed Jul 30, 2024
1 parent d6eb5a1 commit 3be25ec
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions dags/library/cern_publication_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from airflow.providers.postgres.operators.postgres import PostgresOperator
from common.utils import get_total_results_count
from executor_config import kubernetes_executor_config
from library.utils import get_url
from library.utils import get_endpoint
from requests.exceptions import ProxyError
from tenacity import retry_if_exception_type, stop_after_attempt


Expand All @@ -19,7 +20,7 @@ def library_cern_publication_records_dag():
@task(multiple_outputs=True, executor_config=kubernetes_executor_config)
def generate_params(key, **kwargs):
year = kwargs["params"].get("year")
url = get_url(key, year)
url = get_endpoint(key, year)
return {
"endpoint": url,
"type_of_query": key,
Expand All @@ -32,7 +33,7 @@ def fetch_count(parameters):
endpoint=parameters["endpoint"],
_retry_args={
"stop": stop_after_attempt(3),
"retry": retry_if_exception_type(Exception),
"retry": retry_if_exception_type(ProxyError),
},
)
count = get_total_results_count(response.text)
Expand Down
3 changes: 2 additions & 1 deletion dags/open_access/gold_open_access_mechanisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from airflow.providers.postgres.operators.postgres import PostgresOperator
from common.utils import get_total_results_count
from executor_config import kubernetes_executor_config
from requests.exceptions import ProxyError
from tenacity import retry_if_exception_type, stop_after_attempt


Expand Down Expand Up @@ -42,7 +43,7 @@ def fetch_count(parameters):
endpoint=parameters["endpoint"],
_retry_args={
"stop": stop_after_attempt(3),
"retry": retry_if_exception_type(Exception),
"retry": retry_if_exception_type(ProxyError),
},
)
count = get_total_results_count(response.text)
Expand Down
3 changes: 2 additions & 1 deletion dags/open_access/open_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from airflow.providers.postgres.operators.postgres import PostgresOperator
from common.utils import get_total_results_count
from executor_config import kubernetes_executor_config
from requests.exceptions import ProxyError
from tenacity import retry_if_exception_type, stop_after_attempt


Expand Down Expand Up @@ -43,7 +44,7 @@ def fetch_count(parameters):
endpoint=parameters["endpoint"],
_retry_args={
"stop": stop_after_attempt(3),
"retry": retry_if_exception_type(Exception),
"retry": retry_if_exception_type(ProxyError),
},
)
type_of_query = parameters["type_of_query"]
Expand Down
3 changes: 2 additions & 1 deletion dags/open_access/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
get_golden_access_records_ids,
get_green_access_records_ids,
)
from requests.exceptions import ProxyError
from tenacity import retry_if_exception_type, stop_after_attempt


Expand All @@ -20,7 +21,7 @@ def get_count_http_hook(total, url, record_extractor):
endpoint=full_url,
_retry_args={
"stop": stop_after_attempt(3),
"retry": retry_if_exception_type(Exception),
"retry": retry_if_exception_type(ProxyError),
},
)
records_ids_count = records_ids_count + len(record_extractor(response.text))
Expand Down

0 comments on commit 3be25ec

Please sign in to comment.