Skip to content

Commit

Permalink
Add wait_seconds and wait_http_200 options for StepConfig (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
acostapazo authored Apr 20, 2020
1 parent 3481501 commit ea76d30
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
10 changes: 10 additions & 0 deletions examples/lume-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ steps:
setup: echo ${SETUP_MSG}
teardown: echo ${TEADOWN_MSG}
run: echo ${RUN_MSG}
wait-example-seconds:
wait_seconds: 2
run: echo "Done"
wait-example-http:
wait_http_200: https://www.google.com
run: echo "Done"
wait-example-both:
wait_seconds: 2
wait_http_200: https://www.google.com
run: echo "Done"



Expand Down
4 changes: 4 additions & 0 deletions lume/config/step_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class StepConfig:
setup: Optional[List[str]] = None
teardown: Optional[List[str]] = None
setup_detach: Optional[Dict] = None
wait_seconds: Optional[str] = None
wait_http_200: Optional[str] = None

@staticmethod
def from_dict(kdict):
Expand All @@ -29,4 +31,6 @@ def from_dict(kdict):
setup=setup,
teardown=teardown,
setup_detach=setup_detach,
wait_seconds=kdict.get("wait_seconds"),
wait_http_200=kdict.get("wait_http_200"),
)
27 changes: 26 additions & 1 deletion lume/src/application/use_cases/lume_use_case.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import time
import requests
from typing import List, Tuple

from meiga import Result, Error, Success, Failure, isSuccess, isFailure
Expand All @@ -16,6 +18,8 @@
COMMAND,
ENVAR,
ENVAR_WARNING,
WAITING,
INFO,
)
from lume.src.domain.services.interface_setup_service import ISetupService
from lume.src.application.use_cases.messages import get_colored_command_message
Expand Down Expand Up @@ -75,7 +79,6 @@ def execute(self, steps: List[str]):
self.logger.log(ERROR, f"Setup: {result.value}")
result.unwrap_or_return()
else:

cwd = (
self.get_cwd(step)
.handle(on_failure=on_error_with_cwd, failure_args=(self, step))
Expand Down Expand Up @@ -142,8 +145,30 @@ def run_teardown_detach(self, processes):
for process in processes:
self.detach_killer_service.execute(process)

def wait_if_necessary(self, action):
if action == "install":
return
else:
step = self.config.steps.get(action)
if not step.wait_seconds and not step.wait_http_200:
return
if step.wait_seconds:
self.logger.log(WAITING, f"Waiting {step.wait_seconds} seconds")
time.sleep(step.wait_seconds)

if step.wait_http_200:
self.logger.log(WAITING, f"Waiting for 200 -> {step.wait_http_200}")
for i in range(5):
response = requests.get(step.wait_http_200)
self.logger.log(INFO, f" Attempt {i+1} -> {response.status_code}")
if response.status_code == 200:
break
time.sleep(1)
return

@meiga
def run_commands(self, step, cwd, processes) -> Result:
self.wait_if_necessary(step)
commands = (
self.get_commands(step)
.handle(on_failure=on_empty_config, failure_args=(self, step))
Expand Down
1 change: 1 addition & 0 deletions lume/src/domain/services/interface_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
COMMAND = 60
ENVAR = 70
ENVAR_WARNING = 80
WAITING = 90
WARNING = 30
WARN = WARNING
INFO = 20
Expand Down
2 changes: 2 additions & 0 deletions lume/src/infrastructure/services/logger/emojis_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
COMMAND,
ENVAR,
ENVAR_WARNING,
WAITING,
)
from lume.src.infrastructure.services.logger.colors import Colors

Expand All @@ -19,6 +20,7 @@
WARNING: emoji.emojize("🧐"),
ENVAR: emoji.emojize("➕"),
ENVAR_WARNING: emoji.emojize("➕"),
WAITING: emoji.emojize("🕐"),
}


Expand Down

0 comments on commit ea76d30

Please sign in to comment.