From 1fe65ff6b783a05e701bfd3bdd4912358508f2cf Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Mon, 24 Jan 2022 12:40:50 -0500 Subject: [PATCH] Script to get a workflow spec from a workflow id. --- crc/scripts/get_spec_from_workflow_id.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 crc/scripts/get_spec_from_workflow_id.py diff --git a/crc/scripts/get_spec_from_workflow_id.py b/crc/scripts/get_spec_from_workflow_id.py new file mode 100644 index 00000000..78f16787 --- /dev/null +++ b/crc/scripts/get_spec_from_workflow_id.py @@ -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)