Skip to content

Commit

Permalink
Merge pull request #632 from golemfactory/scx1332/timeouts
Browse files Browse the repository at this point in the history
Added more info about time steps. Trying to prevent timeouts in future.
  • Loading branch information
nieznanysprawiciel authored Sep 11, 2023
2 parents e08cf3c + f399163 commit 5cf9809
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# [0.15.1] - 2023-09-11

- Add info & warning that help with detecting potential timeouts in tasks.

# [0.15.0] - 2023-06-28

- Fix schema IDs
Expand Down
20 changes: 18 additions & 2 deletions goth/runner/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@
if TYPE_CHECKING:
from goth.runner.probe import Probe


logger = logging.getLogger(__name__)

TIMEOUT_LEFT_WARNING_THRESHOLD = 5.0


def _check_timeout_and_warn(step_name: str, step_time: float, timeout: float):
if timeout - step_time < TIMEOUT_LEFT_WARNING_THRESHOLD:
logger.warning(
"Step '%s' was very close to being timed out: %.1f s."
" - consider increasing time limit for this step.",
step_name,
timeout - step_time,
)


def step(default_timeout: float = 10.0):
"""Wrap a step function to implement timeout and log progress."""
Expand Down Expand Up @@ -42,12 +53,17 @@ async def wrapper(self: "Probe", *args, timeout: Optional[float] = None):
except Exception as exc:
step_time = time.time() - start_time
logger.error(
"Step '%s' raised %s in %.1f",
"Step '%s' raised %s in %.1f/%.1f s",
step_name,
exc.__class__.__name__,
step_time,
timeout,
)
_check_timeout_and_warn(step_name, step_time, timeout)
raise
step_time = time.time() - start_time
logger.info("Step '%s' finished: %.1f/%.1f s", step_name, step_time, timeout)
_check_timeout_and_warn(step_name, step_time, timeout)
return result

return wrapper
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exclude = '/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|venv|\.svn|_build

[tool.poetry]
name = "goth"
version = "0.15.0"
version = "0.15.1"
description = "Golem Test Harness - integration testing framework"
authors = ["Golem Factory <[email protected]>"]
license = "GPL-3.0"
Expand Down

0 comments on commit 5cf9809

Please sign in to comment.