Skip to content

Commit

Permalink
fix: spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
MehmedGIT committed Dec 18, 2024
1 parent 442682c commit f909816
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 39 deletions.
55 changes: 22 additions & 33 deletions src/server/operandi_server/routers/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,21 +508,17 @@ async def convert_txt_to_nextflow(
return FileResponse(nf_script_dest, filename=f'{oton_id}.nf', media_type="application/txt-file")

async def upload_batch_workflow_scripts(
self,
workflows: List[UploadFile],
auth: HTTPBasicCredentials = Depends(HTTPBasic())
self, workflows: List[UploadFile], auth: HTTPBasicCredentials = Depends(HTTPBasic())
) -> List[WorkflowRsrc]:
"""
Curl equivalent:
`curl -X POST SERVER_ADDR/batch-workflows -F "[email protected]" -F "[email protected]" ...`
"""
py_user_action = await user_auth_with_handling(self.logger, auth)

if len(workflows) > 5:
message = "Batch upload exceeds the limit of 5 workflows"
self.logger.error(message)
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=message)

workflow_resources = []
for workflow in workflows:
try:
Expand All @@ -543,47 +539,40 @@ async def upload_batch_workflow_scripts(
)
workflow_resources.append(WorkflowRsrc.from_db_workflow(db_workflow))
except Exception as error:
message = f"Failed to process workspace {workflow.filename}"
message = f"Failed to process workflow {workflow.filename}"
self.logger.error(f"{message}, error: {error}")
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=message)
return workflow_resources

async def submit_batch_workflow_jobs(
self,
batch_requests: List[dict],
auth: HTTPBasicCredentials = Depends(HTTPBasic())
self, workflow_job_requests: List[dict], auth: HTTPBasicCredentials = Depends(HTTPBasic())
) -> List[WorkflowJobRsrc]:
if len(batch_requests) > 5:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="You can only trigger up to 5 workflow jobs at a time."
)
job_results = []

for request in batch_requests:
py_user_action = await user_auth_with_handling(self.logger, auth)
if len(workflow_job_requests) > 5:
message = "Batch upload exceeds the limit of 5 workflow jobs"
self.logger.error(message)
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=message)
workflow_job_resources = []
for workflow_job_request in workflow_job_requests:
try:
workflow_id = request.get("workflow_id")
workflow_args = WorkflowArguments(**request.get("workflow_args", {}))
sbatch_args = SbatchArguments(**request.get("sbatch_args", {}))
details = request.get("details", "Batch workflow job")

workflow_id = workflow_job_request.get("workflow_id")
workflow_args = WorkflowArguments(**workflow_job_request.get("workflow_args", {}))
sbatch_args = SbatchArguments(**workflow_job_request.get("sbatch_args", {}))
details = workflow_job_request.get("details", "Batch workflow job")
job_result = await self.submit_to_rabbitmq_queue(
workflow_id=workflow_id,
workflow_args=workflow_args,
sbatch_args=sbatch_args,
details=details,
auth=auth
)
job_results.append(job_result)

workflow_job_resources.append(job_result)
except Exception as error:
self.logger.error(f"Failed to submit workflow job for request {request}: {error}")
message = f"Failed to submit workflow job for request {workflow_job_request}: {error}"
self.logger.error(message)
continue # Skip to the next job in the batch

if not job_results:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Failed to trigger any workflow jobs."
)

return job_results
if not workflow_job_resources:
message = "Failed to trigger any workflow jobs."
self.logger.error(f"{message}")
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=message)
return workflow_job_resources
7 changes: 1 addition & 6 deletions src/server/operandi_server/routers/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,21 @@ async def remove_file_group_from_workspace(
return WorkspaceRsrc.from_db_workspace(db_workspace)

async def upload_batch_workspaces(
self,
workspaces: List[UploadFile],
auth: HTTPBasicCredentials = Depends(HTTPBasic()),
self, workspaces: List[UploadFile], auth: HTTPBasicCredentials = Depends(HTTPBasic())
) -> List[WorkspaceRsrc]:
"""
Curl equivalent:
`curl -X POST SERVER_ADDR/batch-workspaces -F [email protected] -F [email protected] ...`
"""
py_user_action = await user_auth_with_handling(self.logger, auth)

if len(workspaces) > 5:
message = "Batch upload exceeds the limit of 5 workspaces"
self.logger.error(message)
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=message)

workspace_resources = []
for workspace in workspaces:
ws_id, ws_dir = create_resource_dir(SERVER_WORKSPACES_ROUTER)
bag_dest = f"{ws_dir}.zip"

try:
await receive_resource(file=workspace, resource_dst=bag_dest)
rmtree(ws_dir, ignore_errors=True)
Expand Down

0 comments on commit f909816

Please sign in to comment.