.
This commit is contained in:
+21
-11
@@ -126,19 +126,23 @@ NB_MAX_WORKERS = (
|
||||
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 2 vérification d'une meme BAL
|
||||
# Interval en minute minimum entre deux repassse
|
||||
MIN_INTERVAL_MINUTES = 15
|
||||
|
||||
# Continue a synchro après le finish
|
||||
MINUTES_AFTER_FINISH = 60
|
||||
|
||||
# toutes les X minutes
|
||||
PRIORITY_INTERVAL_MINUTES = 2
|
||||
|
||||
TABLE_BALS = require_env("TABLE_BALS")
|
||||
COL_EMAIL = require_env("COL_EMAIL")
|
||||
COL_SYNC = require_env("COL_SYNC")
|
||||
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_LAST_PASS = require_env("COL_LAST_PASS")
|
||||
COL_FINISH_TIME = require_env("COL_FINISH_TIME")
|
||||
|
||||
TABLE_HISTORIQUE = require_env("TABLE_HISTORIQUE")
|
||||
COL_BAL = require_env("COL_BAL")
|
||||
@@ -219,7 +223,7 @@ def renew_oauth2_token(dry: bool) -> bool:
|
||||
def run_tests() -> bool:
|
||||
http.client.HTTPConnection.debuglevel = 1
|
||||
print(f" → priority: {grist_fetch_priority_bals()}")
|
||||
print(f" → repasses: {grist_fetch_repass_bals()}")
|
||||
# print(f" → repasses: {grist_fetch_repass_bals()}")
|
||||
return True
|
||||
|
||||
|
||||
@@ -247,7 +251,7 @@ def grist_fetch_new_bals() -> list[dict]:
|
||||
params = {
|
||||
# "limit": NB_CONCURENT_NEW_BAL,
|
||||
"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,
|
||||
}
|
||||
@@ -293,7 +297,7 @@ def grist_fetch_repass_bals() -> list[dict]:
|
||||
params = {
|
||||
# "limit": NB_CONCURENT_REPASS_BAL,
|
||||
"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,
|
||||
}
|
||||
@@ -356,9 +360,7 @@ def grist_fetch_priority_bals() -> list[dict]:
|
||||
# 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], COL_SUCCESS: [True]}
|
||||
),
|
||||
"filter": json.dumps({COL_FINI: [True], COL_SUCCESS: [True]}),
|
||||
"sort": COL_LAST_PASS,
|
||||
}
|
||||
resp = requests.get(
|
||||
@@ -370,13 +372,13 @@ def grist_fetch_priority_bals() -> list[dict]:
|
||||
|
||||
resp.raise_for_status()
|
||||
records = resp.json().get("records", [])
|
||||
|
||||
filtered_bals = []
|
||||
current_timestamp = time.time()
|
||||
|
||||
for r in records:
|
||||
fields = r["fields"]
|
||||
last_pass_timestamp = fields.get(COL_LAST_PASS)
|
||||
finish_timestamp = fields.get(COL_FINISH_TIME)
|
||||
|
||||
elapsed_time = current_timestamp - float(last_pass_timestamp)
|
||||
if elapsed_time < PRIORITY_INTERVAL_MINUTES * 60:
|
||||
@@ -385,7 +387,15 @@ def grist_fetch_priority_bals() -> list[dict]:
|
||||
)
|
||||
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})
|
||||
|
||||
return filtered_bals
|
||||
|
||||
except requests.RequestException as e:
|
||||
|
||||
Reference in New Issue
Block a user