diff --git a/roles/web-app-docs/files/python/infinito_docs/builder.py b/roles/web-app-docs/files/python/infinito_docs/builder.py index ad5852106e..a56c269df1 100644 --- a/roles/web-app-docs/files/python/infinito_docs/builder.py +++ b/roles/web-app-docs/files/python/infinito_docs/builder.py @@ -23,6 +23,7 @@ LATEST = "latest" DEPLOYED = "deployed" LOG_TAIL = 40 QUEUE_SEPARATOR = ":" +RUN_TIMEOUT_SECONDS = 3600 def write_json(path, payload): @@ -64,12 +65,17 @@ class Builder: stderr=subprocess.STDOUT, text=True, ) as process: - for line in process.stdout: - progress = progress_of(line, state["progress"]) - self._append_log(state, line.rstrip()) - if progress != state["progress"]: - state["progress"] = progress - self._save_state(version, **state) + watchdog = threading.Timer(RUN_TIMEOUT_SECONDS, process.kill) + watchdog.start() + try: + for line in process.stdout: + progress = progress_of(line, state["progress"]) + self._append_log(state, line.rstrip()) + if progress != state["progress"]: + state["progress"] = progress + self._save_state(version, **state) + finally: + watchdog.cancel() if process.returncode: raise subprocess.CalledProcessError(process.returncode, command) diff --git a/roles/web-app-docs/files/python/infinito_docs/i18n.py b/roles/web-app-docs/files/python/infinito_docs/i18n.py index e78212781a..ab918e7bac 100644 --- a/roles/web-app-docs/files/python/infinito_docs/i18n.py +++ b/roles/web-app-docs/files/python/infinito_docs/i18n.py @@ -18,6 +18,8 @@ from infinito_docs.commands import generate_commands PACKAGE_DIR = Path(__file__).resolve().parent DOMAIN = "docs" +GENERATE_TIMEOUT_SECONDS = 1800 +EXTRACT_TIMEOUT_SECONDS = 3600 def extract(src: Path, output: Path, jobs: int) -> None: @@ -45,7 +47,13 @@ def extract(src: Path, output: Path, jobs: int) -> None: "PYTHONPATH": os.pathsep.join([str(src), tooling, *inherited]), } for command in generate_commands(src): - subprocess.run(command, check=True, env=env, cwd=scratch) + subprocess.run( + command, + check=True, + env=env, + cwd=scratch, + timeout=GENERATE_TIMEOUT_SECONDS, + ) subprocess.run( [ sys.executable, @@ -65,6 +73,7 @@ def extract(src: Path, output: Path, jobs: int) -> None: check=True, env=env, cwd=scratch, + timeout=EXTRACT_TIMEOUT_SECONDS, ) shutil.copyfile(out / f"{DOMAIN}.pot", output) diff --git a/roles/web-app-docs/files/python/infinito_docs/library.py b/roles/web-app-docs/files/python/infinito_docs/library.py index faab5a6492..58cf311b24 100644 --- a/roles/web-app-docs/files/python/infinito_docs/library.py +++ b/roles/web-app-docs/files/python/infinito_docs/library.py @@ -18,6 +18,7 @@ from .builder import ( from .sites import Sites REFS_TTL_SECONDS = 10 +GIT_TIMEOUT_SECONDS = 900 TAG = re.compile(r"^v(\d+)\.(\d+)\.(\d+)$") @@ -60,6 +61,7 @@ class Library(Sites, Queue, Builder): check=True, capture_output=True, text=True, + timeout=GIT_TIMEOUT_SECONDS, ).stdout def refs(self): @@ -224,6 +226,7 @@ class Library(Sites, Queue, Builder): ], check=True, capture_output=True, + timeout=GIT_TIMEOUT_SECONDS, ) self._forget_refs() self.request(LATEST, background=True) diff --git a/tests/unit/python/roles/web-app-docs/files/infinito_docs/test_builder.py b/tests/unit/python/roles/web-app-docs/files/infinito_docs/test_builder.py index ae0ae99da8..b878a55e67 100644 --- a/tests/unit/python/roles/web-app-docs/files/infinito_docs/test_builder.py +++ b/tests/unit/python/roles/web-app-docs/files/infinito_docs/test_builder.py @@ -7,6 +7,8 @@ through :class:`Library`, on the fixture its sibling module owns. from __future__ import annotations import os +import subprocess +import sys import unittest from unittest.mock import patch @@ -16,6 +18,18 @@ from .test_library import LibraryFixture, _commit, builder, library class TestBuilder(LibraryFixture, unittest.TestCase): + def test_a_run_that_emits_nothing_is_killed_at_the_deadline(self) -> None: + state: dict = {"log": [], "progress": 0} + command = [sys.executable, "-c", "import time; time.sleep(60)"] + + with ( + patch.object(builder, "RUN_TIMEOUT_SECONDS", 0.2), + self.assertRaises(subprocess.CalledProcessError), + ): + self.library._run( + "latest", state, command, dict(os.environ), str(self.data) + ) + def test_latest_is_built_from_the_last_commit(self) -> None: self.library.build("latest")