Skip to content

Commit

Permalink
fix: Importer import_file call: Catch unique import_key errors …
Browse files Browse the repository at this point in the history
…in case an other import was faster (#33)
  • Loading branch information
sveneberth authored Nov 22, 2024
1 parent d678c39 commit f0620e1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/viur/toolkit/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import mimetypes
import numbers
import re
import time
import typing as t

import requests
Expand Down Expand Up @@ -327,7 +328,21 @@ def handle_entries(changes: int, value: t.Any, lang: str | None = None) -> int:
if debug:
logger.debug(f"{bone_name} name {fileName=} is not known")

key = self.import_file(entry["dest"])
for attempt in (rng := range(3)):
try:
key = self.import_file(entry["dest"])
except ValueError as exc:
# Catch unique import_key errors in case an other import was faster
logger.error(f'{entry["dest"]=}')
logger.exception(exc)
if attempt == rng.stop:
raise exc
else:
logger.error(f"Attempt {attempt+1}/{rng.stop} failed")
time.sleep(2 ** attempt)
else:
break

if not key:
continue
# assert (key := self.import_file(entry["dest"]))
Expand Down

0 comments on commit f0620e1

Please sign in to comment.