api/ants: prevent too long transactions when pushing rdvs (#83553)
gitea/ants-hub/pipeline/head This commit looks good Details

This commit is contained in:
Benjamin Dauvergne 2023-11-15 17:58:26 +01:00
parent 64cbac4ccc
commit 498febe19c
1 changed files with 11 additions and 9 deletions

View File

@ -93,19 +93,21 @@ def get_rdvs_to_upload():
def upload_rdvs():
# get never uploaded rdvs and rdv uploaded which changed (cancelled)
with atomic():
rdvs = get_rdvs_to_upload().select_for_update(of=('self',)).distinct()
start = now()
pushed = set()
for rdv in rdvs:
rdvs = get_rdvs_to_upload()
start = now()
for rdv in rdvs.distinct():
with atomic():
try:
rdv = rdvs.select_for_update(of=('self',)).get(pk=rdv.pk)
except RendezVous.DoesNotExist:
continue
try:
if push_rdv(rdv):
pushed.add(rdv)
logger.info('pushed rdv(%s) of lieu %s', rdv, rdv.lieu)
rdv.last_upload = start
rdv.save()
except ANTSError as e:
logger.warning('unable to push rdv(%s) of lieu %s: %r', rdv, rdv.lieu, e)
rdvs.filter(pk__in=[rdv.pk for rdv in pushed]).update(last_upload=start)
for rdv in pushed:
logger.info('pushed rdv(%s) of lieu %s', rdv, rdv.lieu)
def get_status_of_predemandes(identifiant_predemandes: list):