Ajout système de priorisation de synchro : grist_priority_bals.\n modif systemd
This commit is contained in:
@@ -436,6 +436,40 @@ def grist_fetch_bals() -> list[dict]:
|
||||
return []
|
||||
|
||||
|
||||
def grist_priority_bals() -> 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.
|
||||
"""
|
||||
try:
|
||||
# 1. Récupération triée via l'API Grist
|
||||
params = {"limit": 1, "filter": {"priority": [True], COL_SYNC: [True]}}
|
||||
resp = requests.get(
|
||||
grist_url(TABLE_BALS), headers=GRIST_HEADERS, params=params, timeout=15
|
||||
)
|
||||
resp.raise_for_status()
|
||||
records = resp.json().get("records", [])
|
||||
|
||||
# for r in records:
|
||||
r = records[0]
|
||||
fields = r["fields"]
|
||||
|
||||
# Vérification de la condition de synchronisation globale
|
||||
if fields.get(COL_SYNC) is not True:
|
||||
return {}
|
||||
|
||||
# Si le timestamp existe, on valide l'écart de temps
|
||||
if fields.get("Date_derniere_passe") is not None:
|
||||
return {}
|
||||
|
||||
return r
|
||||
|
||||
except requests.RequestException as e:
|
||||
log.error(f"Erreur lecture Grist BALS : {e}")
|
||||
return {}
|
||||
|
||||
|
||||
def grist_add_historique(
|
||||
email: str,
|
||||
status: str,
|
||||
@@ -754,6 +788,14 @@ def main():
|
||||
futures[f] = email
|
||||
log.info(f"[{email}] Job soumis au pool")
|
||||
|
||||
# Ajout de la BAL prioritaire
|
||||
row = grist_priority_bals()
|
||||
email = row.get(COL_EMAIL, "").strip()
|
||||
if email not in _running and email != "":
|
||||
f = pool.submit(run_sync_job, row, dry)
|
||||
futures[f] = email
|
||||
log.info(f"[{email}] Job soumis au pool")
|
||||
|
||||
if not _shutdown:
|
||||
time.sleep(POLL_INTERVAL)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user