This commit is contained in:
2026-06-16 02:18:26 +02:00
parent 590a7dd8c6
commit 4ffa83b47c
+11 -17
View File
@@ -218,7 +218,8 @@ def renew_oauth2_token(dry: bool) -> bool:
# ───────────────────────────────────────────── # ─────────────────────────────────────────────
def run_tests() -> bool: def run_tests() -> bool:
http.client.HTTPConnection.debuglevel = 1 http.client.HTTPConnection.debuglevel = 1
print(f" → payload: {grist_fetch_new_bals()}") print(f" → priority: {grist_fetch_priority_bals()}")
print(f" → repasses: {grist_fetch_repass_bals()}")
return True return True
@@ -317,7 +318,6 @@ def grist_fetch_repass_bals() -> list[dict]:
# Si le timestamp existe, on valide l'écart de temps # Si le timestamp existe, on valide l'écart de temps
if last_pass_timestamp is not None: if last_pass_timestamp is not None:
continue
try: try:
# Calcul du temps écoulé depuis la dernière passe # Calcul du temps écoulé depuis la dernière passe
elapsed_time = current_timestamp - float(last_pass_timestamp) elapsed_time = current_timestamp - float(last_pass_timestamp)
@@ -346,18 +346,19 @@ def grist_fetch_repass_bals() -> list[dict]:
return [] return []
def grist_fetch_priority_bals() -> dict: def grist_fetch_priority_bals() -> list[dict]:
""" """
Retourne les BAL où Synchronisation = True. Retourne les BAL où Synchronisation = True.
Trié par 'Date_derniere_passe' (le plus vieux en premier). Trié par 'Date_derniere_passe' (le plus vieux en premier).
Exclut les BAL dont la dernière passe a eu lieu il y a moins de MIN_INTERVAL_MINUTES. Exclut les BAL dont la dernière passe a eu lieu il y a moins de MIN_INTERVAL_MINUTES.
""" """
log.info("grist_priority_bals")
try: try:
# 1. Récupération triée via l'API Grist # 1. Récupération triée via l'API Grist
params = { params = {
# "limit": NB_CONCURENT_PRIORITY_BAL, # "limit": NB_CONCURENT_PRIORITY_BAL,
"filter": json.dumps({COL_PRIORITY: [True], COL_SYNC: [True]}), "filter": json.dumps(
{COL_PRIORITY: [True], COL_SYNC: [True], COL_SUCCESS: [True]}
),
"sort": COL_LAST_PASS, "sort": COL_LAST_PASS,
} }
resp = requests.get( resp = requests.get(
@@ -370,22 +371,15 @@ def grist_fetch_priority_bals() -> dict:
resp.raise_for_status() resp.raise_for_status()
records = resp.json().get("records", []) records = resp.json().get("records", [])
r = records[0] filtered_bals = []
for r in records:
fields = r["fields"] fields = r["fields"]
filtered_bals.append({"id": r["id"], **fields})
# Vérification de la condition de synchronisation globale return filtered_bals
if fields.get(COL_SYNC) is not True:
return {}
# Au moins une passe déjà faite
if fields.get("Date_derniere_passe") is None:
return {}
return r
except requests.RequestException as e: except requests.RequestException as e:
log.error(f"Erreur lecture Grist BALS : {e}") log.error(f"Erreur lecture Grist BALS : {e}")
return {} return []
def grist_add_historique( def grist_add_historique(