Skip to content

Commit

Permalink
Disable apiclient in test mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wvangeit committed Jun 24, 2024
1 parent ac0a6ca commit 64adcbc
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN apt-get install --yes --no-install-recommends python3 python-is-python3 pyth
# Copying boot scripts
COPY docker_scripts /docker

RUN pip3 install pathos osparc --upgrade
RUN pip3 install pathos osparc pydantic-settings osparc-filecomms --upgrade

USER osparcuser

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SHELL = /bin/sh
.DEFAULT_GOAL := help
MAKEFLAGS += -j2

export DOCKER_IMAGE_NAME ?= osparc-map
export DOCKER_IMAGE_NAME ?= osparc-meta-parallelrunner
export DOCKER_IMAGE_TAG ?= 0.0.14

export MASTER_AWS_REGISTRY ?= registry.osparc-master-zmt.click
Expand Down
2 changes: 1 addition & 1 deletion docker_scripts/entrypoint.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail
IFS=$'\n\t'
INFO="INFO: [$(basename "$0")] "

echo "$INFO" "Starting container for map ..."
echo "$INFO" "Starting container for parallelrunner ..."

HOST_USERID=$(stat -c %u "${DY_SIDECAR_PATH_INPUTS}")
HOST_GROUPID=$(stat -c %g "${DY_SIDECAR_PATH_INPUTS}")
Expand Down
51 changes: 34 additions & 17 deletions docker_scripts/parallelrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(
max_job_create_attempts=MAX_JOB_CREATE_ATTEMPTS,
):
"""Constructor"""
self.test_mode = False

self.batch_mode = batch_mode
self.max_n_of_workers = max_n_of_workers
Expand Down Expand Up @@ -89,8 +90,12 @@ def setup(self):
username=os.environ["OSPARC_API_KEY"],
password=os.environ["OSPARC_API_SECRET"],
)
self.api_client = osparc.ApiClient(self.osparc_cfg)
self.studies_api = osparc_client.StudiesApi(self.api_client)
if self.test_mode:
self.api_client = None
self.studies_api = None
else:
self.api_client = osparc.ApiClient(self.osparc_cfg)
self.studies_api = osparc_client.StudiesApi(self.api_client)

def start(self):
"""Start the Python Runner"""
Expand Down Expand Up @@ -133,6 +138,11 @@ def start(self):
if self.template_id is None:
raise ValueError("Template ID can't be None")

if self.template_id == "TEST_UUID":
self.test_mode = True
self.api_client = None
self.studies_api = None

n_of_workers = key_values[N_OF_WORKERS_KEY]["value"]
if n_of_workers is None:
raise ValueError("Number of workers can't be None")
Expand Down Expand Up @@ -247,20 +257,26 @@ def create_job_inputs(self, batch):
tmp_input_file_path = tmp_dir_path / param_filename
tmp_input_file_path.write_text(json.dumps(param_value))

input_data_file = osparc.FilesApi(
self.api_client
).upload_file(file=tmp_input_file_path)
processed_param_value = input_data_file
if self.test_mode:
processed_param_value = None
else:
input_data_file = osparc.FilesApi(
self.api_client
).upload_file(file=tmp_input_file_path)
processed_param_value = input_data_file
elif param_type == "file":
file_info = json.loads(param_value)
input_data_file = osparc_client.models.file.File(
id=file_info["id"],
filename=file_info["filename"],
content_type=file_info["content_type"],
checksum=file_info["checksum"],
e_tag=file_info["e_tag"],
)
processed_param_value = input_data_file
if self.test_mode:
processed_param_value = None
else:
input_data_file = osparc_client.models.file.File(
id=file_info["id"],
filename=file_info["filename"],
content_type=file_info["content_type"],
checksum=file_info["checksum"],
e_tag=file_info["e_tag"],
)
processed_param_value = input_data_file
elif param_type == "integer":
processed_param_value = int(param_value)
elif param_type == "float":
Expand All @@ -285,7 +301,7 @@ def run_job(self, job_inputs):

logger.debug(f"Sending inputs: {job_inputs}")

if self.template_id == "TEST_UUID":
if self.test_mode:
logger.info("Map in test mode, just returning input")
self.n_of_finished_batches += 1

Expand Down Expand Up @@ -423,8 +439,9 @@ def map_func(batch, trial_number=1):
return output_tasks

def teardown(self):
logger.info("Closing map ...")
self.api_client.close()
logger.info("Closing parallelrunner ...")
if self.api_client:
self.api_client.close()

def read_keyvalues(self):
"""Read keyvalues file"""
Expand Down
2 changes: 0 additions & 2 deletions docker_scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
osparc_filecomms
pydantic-settings

0 comments on commit 64adcbc

Please sign in to comment.