-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
2 changed files
with
23 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -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 |
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 |
---|---|---|
|
@@ -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) | ||
|