Skip to content

Commit

Permalink
refactor(metrics): use simple_connection_retry
Browse files Browse the repository at this point in the history
  • Loading branch information
hacherix committed Dec 23, 2024
1 parent ba6c769 commit 39a607e
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions dgv/metrics/task_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
AIRFLOW_DAG_TMP,
MINIO_BUCKET_INFRA,
)
from datagouvfr_data_pipelines.utils.retry import simple_connection_retry
from datagouvfr_data_pipelines.utils.download import download_files
from datagouvfr_data_pipelines.utils.minio import MinIOClient, File as MinioFile
from datagouvfr_data_pipelines.utils.postgres import (
Expand Down Expand Up @@ -515,6 +516,7 @@ def process_log(ti):
ti.xcom_push(key="dates_processed", value=dates_processed)


@simple_connection_retry
def get_matomo_outlinks(model, slug, target, metric_date):
matomo_url = "https://stats.data.gouv.fr/index.php"
params = {
Expand All @@ -528,14 +530,7 @@ def get_matomo_outlinks(model, slug, target, metric_date):
"period": "day",
"date": metric_date.isoformat(),
}
tries = 5
while tries > 0:
matomo_res = requests.get(matomo_url, params=params)
# The Matomo API is sometimes unstable and required a few retries
if matomo_res.status_code in ["502"]:
time.sleep(0.5)
tries-=1
break
matomo_res = requests.get(matomo_url, params=params)
matomo_res.raise_for_status()
return sum(
outlink["nb_hits"]
Expand Down

0 comments on commit 39a607e

Please sign in to comment.