-
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.
- Loading branch information
1 parent
d04ac27
commit c31501e
Showing
20 changed files
with
531 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# REST API | ||
|
||
To run REST API in local environment, from the root directory of the project run: | ||
|
||
```bash | ||
uvicorn rest.main:app --host 0.0.0.0 --port 8000 --workers 4 --reload | ||
``` |
Empty file.
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import boto3 | ||
import enum | ||
|
||
from core import settings | ||
from ..core import settings | ||
|
||
|
||
class JobStatus(enum.Enum): | ||
|
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,87 @@ | ||
from pathlib import Path | ||
import docker | ||
|
||
from ..core.logger import logger | ||
from ..models.sorting import ( | ||
RunKwargs, | ||
SourceDataKwargs, | ||
RecordingKwargs, | ||
PreprocessingKwargs, | ||
SorterKwargs, | ||
PostprocessingKwargs, | ||
CurationKwargs, | ||
VisualizationKwargs, | ||
) | ||
|
||
|
||
class LocalDockerClient: | ||
|
||
def __init__(self, base_url: str = "tcp://docker-proxy:2375"): | ||
self.logger = logger | ||
self.client = docker.DockerClient(base_url=base_url) | ||
|
||
def run_sorting( | ||
self, | ||
run_kwargs: RunKwargs, | ||
source_data_kwargs: SourceDataKwargs, | ||
recording_kwargs: RecordingKwargs, | ||
preprocessing_kwargs: PreprocessingKwargs, | ||
sorter_kwargs: SorterKwargs, | ||
postprocessing_kwargs: PostprocessingKwargs, | ||
curation_kwargs: CurationKwargs, | ||
visualization_kwargs: VisualizationKwargs, | ||
) -> None: | ||
# Pass kwargs as environment variables to the container | ||
env_vars = dict( | ||
SI_RUN_KWARGS=run_kwargs.json(), | ||
SI_SOURCE_DATA_KWARGS=source_data_kwargs.json(), | ||
SI_RECORDING_KWARGS=recording_kwargs.json(), | ||
SI_PREPROCESSING_KWARGS=preprocessing_kwargs.json(), | ||
SI_SORTER_KWARGS=sorter_kwargs.json(), | ||
SI_POSTPROCESSING_KWARGS=postprocessing_kwargs.json(), | ||
SI_CURATION_KWARGS=curation_kwargs.json(), | ||
SI_VISUALIZATION_KWARGS=visualization_kwargs.json(), | ||
) | ||
|
||
# Local volumes to mount | ||
local_directory = Path(".").absolute() | ||
logs_directory = local_directory / "logs" | ||
results_directory = local_directory / "results" | ||
volumes = { | ||
logs_directory: {'bind': '/logs', 'mode': 'rw'}, | ||
results_directory: {'bind': '/results', 'mode': 'rw'}, | ||
} | ||
|
||
container = self.client.containers.run( | ||
image='python:slim', | ||
command=['python', '-c', 'import os; print(os.environ.get("SI_RUN_KWARGS"))'], | ||
detach=True, | ||
environment=env_vars, | ||
volumes=volumes, | ||
device_requests=[ | ||
docker.types.DeviceRequest( | ||
device_ids=["0"], | ||
capabilities=[['gpu']] | ||
) | ||
] | ||
) | ||
# if response.status_code == 200: | ||
# self.logger.info("Success!") | ||
# else: | ||
# self.logger.info(f"Error {response.status_code}: {response.content}") | ||
|
||
|
||
def get_run_logs(self, run_identifier): | ||
# TODO: Implement this | ||
self.logger.info("Getting logs...") | ||
# response = requests.get(self.url + "/logs", params={"run_identifier": run_identifier}) | ||
# if response.status_code == 200: | ||
# logs = response.content.decode('utf-8') | ||
# if "Error running sorter" in logs: | ||
# return "fail", logs | ||
# elif "Sorting job completed successfully!" in logs: | ||
# return "success", logs | ||
# return "running", logs | ||
# else: | ||
# self.logger.info(f"Error {response.status_code}: {response.content}") | ||
# return "fail", f"Logs couldn't be retrieved. Error {response.status_code}: {response.content}" |
File renamed without changes.
Empty file.
Empty file.
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
Oops, something went wrong.