-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ITISFoundation/batch_mode
Batch mode
- Loading branch information
Showing
16 changed files
with
619 additions
and
487 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import http.server | ||
import logging | ||
import pathlib as pl | ||
import socketserver | ||
import threading | ||
import time | ||
import typing | ||
|
||
import pydantic as pyda | ||
import pydantic_settings | ||
|
||
import parallelrunner | ||
|
||
logging.basicConfig( | ||
level=logging.INFO, format="[%(filename)s:%(lineno)d] %(message)s" | ||
) | ||
logger = logging.getLogger(__name__) | ||
|
||
HTTP_PORT = 8888 | ||
INPUT_CONF_KEY = "input_3" | ||
|
||
|
||
def main(): | ||
"""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): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__( | ||
*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: | ||
httpd_thread = threading.Thread(target=httpd.serve_forever) | ||
httpd_thread.start() | ||
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) | ||
|
||
|
||
class MainSettings(pydantic_settings.BaseSettings): | ||
batch_mode: bool = False | ||
file_polling_interval: int = 1 | ||
input_path: pyda.DirectoryPath = pyda.Field(alias="DY_SIDECAR_PATH_INPUTS") | ||
output_path: pyda.DirectoryPath = pyda.Field( | ||
alias="DY_SIDECAR_PATH_OUTPUTS" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.