.
This commit is contained in:
+11
-17
@@ -218,7 +218,8 @@ def renew_oauth2_token(dry: bool) -> bool:
|
||||
# ─────────────────────────────────────────────
|
||||
def run_tests() -> bool:
|
||||
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
|
||||
|
||||
|
||||
@@ -317,7 +318,6 @@ def grist_fetch_repass_bals() -> list[dict]:
|
||||
|
||||
# Si le timestamp existe, on valide l'écart de temps
|
||||
if last_pass_timestamp is not None:
|
||||
continue
|
||||
try:
|
||||
# Calcul du temps écoulé depuis la dernière passe
|
||||
elapsed_time = current_timestamp - float(last_pass_timestamp)
|
||||
@@ -346,18 +346,19 @@ def grist_fetch_repass_bals() -> list[dict]:
|
||||
return []
|
||||
|
||||
|
||||
def grist_fetch_priority_bals() -> dict:
|
||||
def grist_fetch_priority_bals() -> list[dict]:
|
||||
"""
|
||||
Retourne les BAL où Synchronisation = True.
|
||||
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.
|
||||
"""
|
||||
log.info("grist_priority_bals")
|
||||
try:
|
||||
# 1. Récupération triée via l'API Grist
|
||||
params = {
|
||||
# "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,
|
||||
}
|
||||
resp = requests.get(
|
||||
@@ -370,22 +371,15 @@ def grist_fetch_priority_bals() -> dict:
|
||||
resp.raise_for_status()
|
||||
records = resp.json().get("records", [])
|
||||
|
||||
r = records[0]
|
||||
filtered_bals = []
|
||||
for r in records:
|
||||
fields = r["fields"]
|
||||
|
||||
# Vérification de la condition de synchronisation globale
|
||||
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
|
||||
filtered_bals.append({"id": r["id"], **fields})
|
||||
return filtered_bals
|
||||
|
||||
except requests.RequestException as e:
|
||||
log.error(f"Erreur lecture Grist BALS : {e}")
|
||||
return {}
|
||||
return []
|
||||
|
||||
|
||||
def grist_add_historique(
|
||||
|
||||
Reference in New Issue
Block a user