Export Apo: cache inscrits étapes

This commit is contained in:
Emmanuel Viennet 2022-04-22 11:20:06 +02:00
parent 9212f72581
commit 75f8c3b500
2 changed files with 18 additions and 2 deletions

View File

@ -37,12 +37,20 @@ import xml.dom.minidom
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
from app import log from app import log
from app.scodoc import sco_cache
from app.scodoc.sco_exceptions import ScoValueError from app.scodoc.sco_exceptions import ScoValueError
from app.scodoc import sco_preferences from app.scodoc import sco_preferences
SCO_CACHE_ETAPE_FILENAME = os.path.join(scu.SCO_TMP_DIR, "last_etapes.xml") SCO_CACHE_ETAPE_FILENAME = os.path.join(scu.SCO_TMP_DIR, "last_etapes.xml")
class ApoInscritsEtapeCache(sco_cache.ScoDocCache):
"""Cache liste des inscrits à une étape Apogée"""
timeout = 10 * 60 # 10 minutes
prefix = "APOINSCRETAP"
def has_portal(): def has_portal():
"True if we are connected to a portal" "True if we are connected to a portal"
return get_portal_url() return get_portal_url()
@ -139,14 +147,20 @@ get_maquette_url = _PI.get_maquette_url
get_portal_api_version = _PI.get_portal_api_version get_portal_api_version = _PI.get_portal_api_version
def get_inscrits_etape(code_etape, anneeapogee=None, ntrials=2): def get_inscrits_etape(code_etape, anneeapogee=None, ntrials=2, use_cache=True):
"""Liste des inscrits à une étape Apogée """Liste des inscrits à une étape Apogée
Result = list of dicts Result = list of dicts
ntrials: try several time the same request, useful for some bad web services ntrials: try several time the same request, useful for some bad web services
use_cache: use (redis) cache
""" """
log("get_inscrits_etape: code=%s anneeapogee=%s" % (code_etape, anneeapogee)) log("get_inscrits_etape: code=%s anneeapogee=%s" % (code_etape, anneeapogee))
if anneeapogee is None: if anneeapogee is None:
anneeapogee = str(time.localtime()[0]) anneeapogee = str(time.localtime()[0])
if use_cache:
obj = ApoInscritsEtapeCache.get((code_etape, anneeapogee))
if obj:
log("get_inscrits_etape: using cached data")
return obj
etud_url = get_etud_url() etud_url = get_etud_url()
api_ver = get_portal_api_version() api_ver = get_portal_api_version()
@ -189,6 +203,8 @@ def get_inscrits_etape(code_etape, anneeapogee=None, ntrials=2):
return False # ??? pas d'annee d'inscription dans la réponse return False # ??? pas d'annee d'inscription dans la réponse
etuds = [e for e in etuds if check_inscription(e)] etuds = [e for e in etuds if check_inscription(e)]
if use_cache and etuds:
ApoInscritsEtapeCache.set((code_etape, anneeapogee), etuds)
return etuds return etuds

View File

@ -1,7 +1,7 @@
# -*- mode: python -*- # -*- mode: python -*-
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
SCOVERSION = "9.2.8" SCOVERSION = "9.2.9"
SCONAME = "ScoDoc" SCONAME = "ScoDoc"