Skip to content

Commit

Permalink
Make timeout configurable as per review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyestein committed Oct 24, 2024
1 parent e4e6460 commit 7c4d9e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
11 changes: 10 additions & 1 deletion emap-setup/emap_runner/runner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
from datetime import timedelta

from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -100,8 +101,15 @@ def create_parser() -> Parser:
default=False,
action="store_true",
)
validation_parser.add_argument(
"--timeout",
type=lambda h: timedelta(hours=float(h)),
metavar="HOURS",
help="Max time to wait for the validation run to finish",
default=timedelta(hours=10),
)

# add use-FOO and no-use-FOO options for enabling/disabling various services in validation
# flags for enabling/disabling various services in validation
add_boolean_optional_action(validation_parser, "hl7-reader", True, "the main HL7 ADT reader")
add_boolean_optional_action(validation_parser, "hoover", True, "the hoover service")
add_boolean_optional_action(validation_parser, "waveform", False, "waveform reader")
Expand Down Expand Up @@ -212,6 +220,7 @@ def validation(self) -> ValidationRunner:
use_hl7_reader=self.args.use_hl7_reader,
use_hoover=self.args.use_hoover,
use_waveform=self.args.use_waveform,
timeout=self.args.timeout,
)
runner.run()
return runner
Expand Down
7 changes: 4 additions & 3 deletions emap-setup/emap_runner/validation/validation_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class ValidationRunnerException(EMAPRunnerException):


class ValidationRunner:
timeout = timedelta(hours=10)
wait_secs = 120
final_wait_secs = 600

def __init__(
self,
docker_runner: "DockerRunner",
time_window: "TimeWindow",
timeout: timedelta,
should_build: bool = True,
use_hl7_reader: bool = True,
use_hoover: bool = True,
Expand All @@ -35,6 +35,7 @@ def __init__(

self.docker = docker_runner
self.time_window = time_window
self.timeout = timeout

def run(self) -> None:
"""Run a validation run pipeline by constructing services and waiting
Expand Down Expand Up @@ -180,11 +181,11 @@ def _wait_for_queue_to_empty(self) -> None:
while self._has_populated_queues:
time.sleep(ValidationRunner.wait_secs)
elapsed_time = timedelta(seconds=time.monotonic() - start_time_monotonic)
if elapsed_time > ValidationRunner.timeout:
if elapsed_time > self.timeout:
self._save_logs_and_stop()
raise ValidationRunnerException(
f"Waiting for queue timed out. Elapsed time "
f"({elapsed_time}) > timeout ({ValidationRunner.timeout})"
f"({elapsed_time}) > timeout ({self.timeout})"
)

# exits too keenly from databaseExtracts queue, adding in a wait period
Expand Down
5 changes: 3 additions & 2 deletions emap-setup/tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def test_time_window_is_set():
runner = ValidationRunner(
docker_runner=DockerRunner(project_dir=Path.cwd(), config=config),
time_window=TimeWindow(start_date="today", end_date="7 days ago"),
timeout=timedelta(minutes=3),
)

mkdir("config")
Expand Down Expand Up @@ -149,7 +150,7 @@ def test_validation_source_arguments_set_correct_runner_attributes(args_list,
])
def test_validation_timeout(num_trues, timeout_seconds, expect_raises):
parser = create_parser()
args = parser.parse_args(["validation", "--use-waveform"])
args = parser.parse_args(["validation", "--use-waveform", "--timeout", str(timeout_seconds / 3600)])
global_config = GlobalConfiguration(config_path_all)

# simulate having to go through the check and wait loop a variable number of times
Expand All @@ -162,7 +163,7 @@ def inner_mock_has_populated_queues():
return call_count <= num_trues
return inner_mock_has_populated_queues

with patch.multiple(ValidationRunner, timeout=timedelta(seconds=timeout_seconds), wait_secs=0.6, final_wait_secs=0):
with patch.multiple(ValidationRunner, wait_secs=0.6, final_wait_secs=0):
with patch.object(ValidationRunner, '_run_emap', new_callable=MagicMock) as run_emap:
with patch.object(ValidationRunner, '_has_populated_queues', new_callable=PropertyMock) as populated_queues:
with patch.object(ValidationRunner, '_save_logs_and_stop', new_callable=MagicMock) as stop:
Expand Down

0 comments on commit 7c4d9e3

Please sign in to comment.