.
This commit is contained in:
+4
-5
@@ -10,16 +10,15 @@ GRIST_BASE_URL=https://grist.votre-instance.fr
|
|||||||
|
|
||||||
# Tables Grist
|
# Tables Grist
|
||||||
TABLE_BALS=BALs
|
TABLE_BALS=BALs
|
||||||
TABLE_HISTORIQUE=Historique
|
|
||||||
|
|
||||||
# Colonnes Grist TABLE_BALS
|
|
||||||
COL_EMAIL=Courriel #Addresse a synchoniser
|
COL_EMAIL=Courriel #Addresse a synchoniser
|
||||||
COL_SYNC=Synchronisation #Bool si vrai, synchoniser
|
COL_SYNC=Synchronisation #Bool si vrai, synchoniser
|
||||||
COL_PRIORITY=priority
|
COL_FINI=Fini
|
||||||
COL_NB_SYNCS=Nb_syncs #contient le nombre de synchonisation de la BAL
|
COL_NB_SYNCS=Nb_syncs #contient le nombre de synchonisation de la BAL
|
||||||
COL_SUCCESS=Synchonisee_au_moins_une_fois
|
COL_SUCCESS=Synchonisee_au_moins_une_fois
|
||||||
COL_LAST_PASS=Date_derniere_passe
|
COL_LAST_PASS=Date_derniere_passe
|
||||||
# Colonnes Grist TABLE_HISTORIQUE
|
COL_FINISH_TIME=Date_fini
|
||||||
|
|
||||||
|
TABLE_HISTORIQUE=Historique
|
||||||
COL_BAL=Bal
|
COL_BAL=Bal
|
||||||
COL_STATUS=Status
|
COL_STATUS=Status
|
||||||
COL_NB_EMAILS=Nb_emails
|
COL_NB_EMAILS=Nb_emails
|
||||||
|
|||||||
+21
-11
@@ -126,19 +126,23 @@ NB_MAX_WORKERS = (
|
|||||||
NB_CONCURENT_NEW_BAL + NB_CONCURENT_REPASS_BAL + NB_CONCURENT_PRIORITY_BAL
|
NB_CONCURENT_NEW_BAL + NB_CONCURENT_REPASS_BAL + NB_CONCURENT_PRIORITY_BAL
|
||||||
)
|
)
|
||||||
|
|
||||||
# NEW_RATIO = float(opt_env("NEW_RATIO", "0.20"))
|
# Interval en minute minimum entre deux repassse
|
||||||
|
|
||||||
# Interval en minute minimum entre 2 vérification d'une meme BAL
|
|
||||||
MIN_INTERVAL_MINUTES = 15
|
MIN_INTERVAL_MINUTES = 15
|
||||||
|
|
||||||
|
# Continue a synchro après le finish
|
||||||
|
MINUTES_AFTER_FINISH = 60
|
||||||
|
|
||||||
|
# toutes les X minutes
|
||||||
PRIORITY_INTERVAL_MINUTES = 2
|
PRIORITY_INTERVAL_MINUTES = 2
|
||||||
|
|
||||||
TABLE_BALS = require_env("TABLE_BALS")
|
TABLE_BALS = require_env("TABLE_BALS")
|
||||||
COL_EMAIL = require_env("COL_EMAIL")
|
COL_EMAIL = require_env("COL_EMAIL")
|
||||||
COL_SYNC = require_env("COL_SYNC")
|
COL_SYNC = require_env("COL_SYNC")
|
||||||
COL_NB_SYNCS = require_env("COL_NB_SYNCS")
|
COL_NB_SYNCS = require_env("COL_NB_SYNCS")
|
||||||
COL_PRIORITY = require_env("COL_PRIORITY")
|
COL_FINI = require_env("COL_FINI")
|
||||||
COL_SUCCESS = require_env("COL_SUCCESS")
|
COL_SUCCESS = require_env("COL_SUCCESS")
|
||||||
COL_LAST_PASS = require_env("COL_LAST_PASS")
|
COL_LAST_PASS = require_env("COL_LAST_PASS")
|
||||||
|
COL_FINISH_TIME = require_env("COL_FINISH_TIME")
|
||||||
|
|
||||||
TABLE_HISTORIQUE = require_env("TABLE_HISTORIQUE")
|
TABLE_HISTORIQUE = require_env("TABLE_HISTORIQUE")
|
||||||
COL_BAL = require_env("COL_BAL")
|
COL_BAL = require_env("COL_BAL")
|
||||||
@@ -219,7 +223,7 @@ 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" → priority: {grist_fetch_priority_bals()}")
|
print(f" → priority: {grist_fetch_priority_bals()}")
|
||||||
print(f" → repasses: {grist_fetch_repass_bals()}")
|
# print(f" → repasses: {grist_fetch_repass_bals()}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@@ -247,7 +251,7 @@ def grist_fetch_new_bals() -> list[dict]:
|
|||||||
params = {
|
params = {
|
||||||
# "limit": NB_CONCURENT_NEW_BAL,
|
# "limit": NB_CONCURENT_NEW_BAL,
|
||||||
"filter": json.dumps(
|
"filter": json.dumps(
|
||||||
{COL_PRIORITY: [False], COL_SYNC: [True], COL_SUCCESS: [False]}
|
{COL_FINI: [False], COL_SYNC: [True], COL_SUCCESS: [False]}
|
||||||
),
|
),
|
||||||
"sort": COL_LAST_PASS,
|
"sort": COL_LAST_PASS,
|
||||||
}
|
}
|
||||||
@@ -293,7 +297,7 @@ def grist_fetch_repass_bals() -> list[dict]:
|
|||||||
params = {
|
params = {
|
||||||
# "limit": NB_CONCURENT_REPASS_BAL,
|
# "limit": NB_CONCURENT_REPASS_BAL,
|
||||||
"filter": json.dumps(
|
"filter": json.dumps(
|
||||||
{COL_PRIORITY: [False], COL_SYNC: [True], COL_SUCCESS: [True]}
|
{COL_FINI: [False], COL_SYNC: [True], COL_SUCCESS: [True]}
|
||||||
),
|
),
|
||||||
"sort": COL_LAST_PASS,
|
"sort": COL_LAST_PASS,
|
||||||
}
|
}
|
||||||
@@ -356,9 +360,7 @@ def grist_fetch_priority_bals() -> list[dict]:
|
|||||||
# 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(
|
"filter": json.dumps({COL_FINI: [True], COL_SUCCESS: [True]}),
|
||||||
{COL_PRIORITY: [True], COL_SYNC: [True], COL_SUCCESS: [True]}
|
|
||||||
),
|
|
||||||
"sort": COL_LAST_PASS,
|
"sort": COL_LAST_PASS,
|
||||||
}
|
}
|
||||||
resp = requests.get(
|
resp = requests.get(
|
||||||
@@ -370,13 +372,13 @@ def grist_fetch_priority_bals() -> list[dict]:
|
|||||||
|
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
records = resp.json().get("records", [])
|
records = resp.json().get("records", [])
|
||||||
|
|
||||||
filtered_bals = []
|
filtered_bals = []
|
||||||
current_timestamp = time.time()
|
current_timestamp = time.time()
|
||||||
|
|
||||||
for r in records:
|
for r in records:
|
||||||
fields = r["fields"]
|
fields = r["fields"]
|
||||||
last_pass_timestamp = fields.get(COL_LAST_PASS)
|
last_pass_timestamp = fields.get(COL_LAST_PASS)
|
||||||
|
finish_timestamp = fields.get(COL_FINISH_TIME)
|
||||||
|
|
||||||
elapsed_time = current_timestamp - float(last_pass_timestamp)
|
elapsed_time = current_timestamp - float(last_pass_timestamp)
|
||||||
if elapsed_time < PRIORITY_INTERVAL_MINUTES * 60:
|
if elapsed_time < PRIORITY_INTERVAL_MINUTES * 60:
|
||||||
@@ -385,7 +387,15 @@ def grist_fetch_priority_bals() -> list[dict]:
|
|||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
elapsed_time = current_timestamp - float(finish_timestamp)
|
||||||
|
if elapsed_time > MINUTES_AFTER_FINISH * 60:
|
||||||
|
log.debug(
|
||||||
|
f"BAL {r['id']} ignorée : Boite fini depuis {int(finish_timestamp // 60)} min."
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
filtered_bals.append({"id": r["id"], **fields})
|
filtered_bals.append({"id": r["id"], **fields})
|
||||||
|
|
||||||
return filtered_bals
|
return filtered_bals
|
||||||
|
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user