Skip to content

Commit

Permalink
Do not fail demo generation when varnish is not reachable
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit74 committed Dec 3, 2024
1 parent cf7d47c commit 9a33a9b
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions zim/demo-library/demo-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def open_chmod(file: Path, mode: str = "r", chmod: int | None = None):
file.chmod(chmod)


logger.info(f"Downloading demo configuration…")
logger.info("Downloading demo configuration…")
resp = requests.get(
assets_base_url + "demos.yaml",
timeout=REQUESTS_TIMEOUT,
Expand All @@ -294,7 +294,7 @@ def open_chmod(file: Path, mode: str = "r", chmod: int | None = None):
resp.raise_for_status()
static_file.write_bytes(resp.content)

logger.info(f"Preparing…")
logger.info("Preparing…")
zims: dict[str, ZimInfo] = {}

jinja_env = Environment(
Expand Down Expand Up @@ -369,15 +369,19 @@ def open_chmod(file: Path, mode: str = "r", chmod: int | None = None):
continue
shutil.rmtree(demos_path / file.name)

logger.info(f"Requesting cache purge…")
resp = requests.request(
method="PURGE",
url=varnish_cache_url,
headers={"X-Purge-Type": "all"},
timeout=REQUESTS_TIMEOUT,
)
if not resp.ok:
logger.error(f"Error while purging cache: HTTP {resp.status_code}/{resp.reason}")

logger.info("Requesting cache purge…")
try:
resp = requests.request(
method="PURGE",
url=varnish_cache_url,
headers={"X-Purge-Type": "all"},
timeout=REQUESTS_TIMEOUT,
)
if not resp.ok:
logger.error(
f"Error while purging cache: HTTP {resp.status_code}/{resp.reason}"
)
except Exception as exc:
logger.error("Error while purging cache", exc_info=exc)

logger.info(f"Done.")
logger.info("Done.")

0 comments on commit 9a33a9b

Please sign in to comment.