Skip to content

Commit

Permalink
Add webserver
Browse files Browse the repository at this point in the history
  • Loading branch information
wvangeit committed Apr 16, 2024
1 parent 38cbfbb commit 6ae73ae
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions docker_scripts/dakota-start.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import contextlib
import http.server
import logging
import os
import pathlib as pl
import shutil
import socketserver
import sys
import threading
import time
import uuid

Expand All @@ -29,11 +32,31 @@
NOISE_SIGMAS = [5.0, 10.0]

POLLING_TIME = 0.1
HTTP_PORT = 8888


def main():
dakota_service = DakotaService()
dakota_service.start()

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

class HTTPHandler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(
*args, **kwargs, directory=http_dir_path.resolve()
)

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:
httpd_thread = threading.Thread(target=httpd.serve_forever)
httpd_thread.start()
dakota_service.start()
httpd.shutdown()
except Exception as err: # pylint: disable=broad-except
logger.error(f"{err} . Stopping %s", exc_info=True)


class DakotaService:
Expand Down Expand Up @@ -87,8 +110,6 @@ def start(self):
self.start_dakota(dakota_conf, self.output0_dir_path)

def model_callback(self, dak_inputs):
# print(f"evaluating: {dak_inputs}")
#
param_sets = [
{
label: value
Expand All @@ -111,7 +132,6 @@ def model_callback(self, dak_inputs):
}
for obj_set, response_labels in zip(obj_sets, all_response_labels)
]
# print(f"output: {dak_outputs}")
return dak_outputs

def model(self, input, mus=NOISE_MUS, sigmas=NOISE_SIGMAS):
Expand Down

0 comments on commit 6ae73ae

Please sign in to comment.