Skip to content

Commit

Permalink
do not create failed jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaelicke committed Mar 27, 2024
1 parent 8b86971 commit b1cb126
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
29 changes: 11 additions & 18 deletions toolbox_runner/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,28 +165,21 @@ def create_job(

# create the job
# this returns the mount points in case they were not pre-defined
did_error = False
try:
in_dir, out_dir = self.runner.init_tool(tool=tool, parameter=parameters, data=data, in_dir=in_dir, out_dir=out_dir)
except Exception as e:
did_error = str(e)
if in_dir is None:
in_dir = 'UNSET'
if out_dir is None:
out_dir = 'UNSET'
warnings.warn(f"TOOL INIT FAILED: {str(e)}")
raise RuntimeError(f"Could not initialize the tool {tool_name} with the given parameters and data. ERROR: {str(e)}")

finally:
# crete the tool job entry
toolJob = ToolJob(
job_id=str(uuid.uuid4()),
docker_image=docker_image,
tool_name=tool_name,
in_dir=in_dir,
out_dir=out_dir,
status=ToolJobStatus.PENDING if not did_error else ToolJobStatus.FAILED,
error_message=did_error if did_error else None
)

# crete the tool job entry
toolJob = ToolJob(
job_id=str(uuid.uuid4()),
docker_image=docker_image,
tool_name=tool_name,
in_dir=in_dir,
out_dir=out_dir,
status=ToolJobStatus.PENDING,
)

# set the job in the store
self._hset(f"tooljob:{toolJob.job_id}", toolJob.model_dump())
Expand Down
13 changes: 8 additions & 5 deletions toolbox_runner/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@ def create_job(
dir = None

# create a new job
job = handler.create_job(tool_name, parameters=parameters, data=local_data)

# delete the temporary directory
if dir is not None:
dir.cleanup()
try:
job = handler.create_job(tool_name, parameters=parameters, data=local_data)
except Exception as e:
raise HTTPException(status_code=400, detail=str(e))
finally:
# delete the temporary directory
if dir is not None:
dir.cleanup()

return job

Expand Down

0 comments on commit b1cb126

Please sign in to comment.