|
| 1 | +import math |
1 | 2 | import re
|
2 | 3 | import shutil
|
3 | 4 | import subprocess
|
4 | 5 | from pathlib import Path
|
5 | 6 | from textwrap import dedent
|
6 | 7 | from uuid import uuid4
|
7 | 8 |
|
| 9 | +from fabric.exceptions import CommandTimeout |
8 | 10 | from git import Repo
|
9 | 11 |
|
10 |
| -from arca.exceptions import ArcaMisconfigured, BuildError |
| 12 | +from arca.exceptions import ArcaMisconfigured, BuildError, BuildTimeoutError |
11 | 13 | from arca.result import Result
|
12 | 14 | from arca.task import Task
|
13 | 15 | from arca.utils import LazySettingProperty, logger
|
@@ -150,7 +152,7 @@ def fabric_task(self):
|
150 | 152 | from fabric import api
|
151 | 153 |
|
152 | 154 | @api.task
|
153 |
| - def run_script(container_name, definition_filename, image_name, image_tag, repository): |
| 155 | + def run_script(container_name, definition_filename, image_name, image_tag, repository, timeout): |
154 | 156 | """ Sequence to run inside the VM.
|
155 | 157 | Starts up the container if the container is not running
|
156 | 158 | (and copies over the data and the runner script)
|
@@ -184,9 +186,11 @@ def run_script(container_name, definition_filename, image_name, image_tag, repos
|
184 | 186 | api.run(f"docker cp /vagrant/{definition_filename} {container_name}:/srv/scripts/")
|
185 | 187 |
|
186 | 188 | output = api.run(" ".join([
|
187 |
| - "docker", "exec", container_name, |
188 |
| - "python", "/srv/scripts/runner.py", f"/srv/scripts/{definition_filename}", |
189 |
| - ])) |
| 189 | + "docker", "exec", container_name, |
| 190 | + "python", "/srv/scripts/runner.py", f"/srv/scripts/{definition_filename}", |
| 191 | + ]), |
| 192 | + timeout=math.ceil(timeout) |
| 193 | + ) |
190 | 194 |
|
191 | 195 | if not self.keep_container_running:
|
192 | 196 | api.run(f"docker kill {container_name}")
|
@@ -261,9 +265,12 @@ def run(self, repo: str, branch: str, task: Task, git_repo: Repo, repo_path: Pat
|
261 | 265 | definition_filename=task_filename,
|
262 | 266 | image_name=image_name,
|
263 | 267 | image_tag=image_tag,
|
264 |
| - repository=str(repo_path.relative_to(Path(self._arca.base_dir).resolve() / 'repos'))) |
| 268 | + repository=str(repo_path.relative_to(Path(self._arca.base_dir).resolve() / 'repos')), |
| 269 | + timeout=task.timeout) |
265 | 270 |
|
266 | 271 | return Result(res[self.vagrant.user_hostname_port()].stdout)
|
| 272 | + except CommandTimeout: |
| 273 | + raise BuildTimeoutError(f"The task timeouted after {task.timeout} seconds.") |
267 | 274 | except BuildError: # can be raised by :meth:`Result.__init__`
|
268 | 275 | raise
|
269 | 276 | except Exception as e:
|
|
0 commit comments