Skip to content

Commit

Permalink
Start fake webserver before looking at inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
wvangeit committed Jul 3, 2024
1 parent e7bbcd1 commit 2833787
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions docker_scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ def main():
settings = MainSettings()
config_path = settings.input_path / INPUT_CONF_KEY / "parallelrunner.json"

waiter = 0
while not config_path.exists():
if waiter % 10 == 0:
logger.info("Waiting for parallelrunner.json to exist ...")
time.sleep(settings.file_polling_interval)
waiter += 1

settings = settings.parse_file(config_path)
logging.info(f"Received the following settings: {settings}")

http_dir_path = pl.Path(__file__).parent / "http"

class HTTPHandler(http.server.SimpleHTTPRequestHandler):
Expand All @@ -44,18 +34,32 @@ def __init__(self, *args, **kwargs):
*args, **kwargs, directory=http_dir_path.resolve()
)

maprunner = parallelrunner.ParallelRunner(**settings.dict())

try:
logger.info(
f"Starting http server at port {HTTP_PORT} and serving path {http_dir_path}"
)
with socketserver.TCPServer(("", HTTP_PORT), HTTPHandler) as httpd:
# First start the empty web server
httpd_thread = threading.Thread(target=httpd.serve_forever)
httpd_thread.start()

# Now start the real parallel runner
waiter = 0
while not config_path.exists():
if waiter % 10 == 0:
logger.info("Waiting for parallelrunner.json to exist ...")
time.sleep(settings.file_polling_interval)
waiter += 1

settings = settings.parse_file(config_path)
logging.info(f"Received the following settings: {settings}")

maprunner = parallelrunner.ParallelRunner(**settings.dict())

maprunner.setup()
maprunner.start()
maprunner.teardown()

httpd.shutdown()
except Exception as err: # pylint: disable=broad-except
logger.error(f"{err} . Stopping %s", exc_info=True)
Expand Down

0 comments on commit 2833787

Please sign in to comment.