Script to get a workflow spec from a workflow id.

This commit is contained in:
mike cullerton 2022-01-24 12:40:50 -05:00
parent e67a1554ea
commit 1fe65ff6b7
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
from crc import session
from crc.api.common import ApiError
from crc.models.workflow import WorkflowModel, WorkflowSpecModel, WorkflowSpecModelSchema
from crc.scripts.script import Script
class ScriptTemplate(Script):
def get_description(self):
return """Get a workflow spec, from a workflow id. You must pass in a workflow id."""
def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs):
return self.do_task(task, study_id, workflow_id, *args, **kwargs)
def do_task(self, task, study_id, workflow_id, *args, **kwargs):
if len(args) < 1:
raise ApiError(code='missing_parameter',
message='Please pass in a workflow_id to use in the search.')
passed_workflow_id = args[0]
workflow = session.query(WorkflowModel).filter(WorkflowModel.id == passed_workflow_id).first()
workflow_spec = session.query(WorkflowSpecModel).filter(WorkflowSpecModel.id==workflow.workflow_spec_id).first()
if workflow_spec:
return WorkflowSpecModelSchema().dump(workflow_spec)