Don't call an api endpoint from a script.

This commit is contained in:
mike cullerton 2022-02-24 11:14:24 -05:00
parent e1bd301e41
commit c1606a20a5
1 changed files with 15 additions and 2 deletions

View File

@ -1,13 +1,26 @@
from crc import session
from crc.api.common import ApiError
from crc.api.workflow import get_workflow
from crc.models.api_models import WorkflowApi, WorkflowApiSchema
from crc.models.workflow import WorkflowModel, WorkflowStatus
from crc.scripts.script import Script
from crc.services.workflow_processor import WorkflowProcessor
from crc.services.workflow_service import WorkflowService
class StartWorkflow(Script):
@staticmethod
def get_workflow(workflow_id):
workflow_model: WorkflowModel = session.query(WorkflowModel).filter_by(id=workflow_id).first()
processor = WorkflowProcessor(workflow_model)
processor.do_engine_steps()
processor.save()
WorkflowService.update_task_assignments(processor)
workflow_api_model = WorkflowService.processor_to_workflow_api(processor)
return WorkflowApiSchema().dump(workflow_api_model)
def get_description(self):
return """Script to start a workflow programmatically.
It requires a workflow_spec_id.
@ -49,8 +62,8 @@ class StartWorkflow(Script):
filter(WorkflowModel.study_id==study_id).\
filter(WorkflowModel.workflow_spec_id==workflow_spec_id).\
first()
workflow_api = get_workflow(workflow.id)
workflow_api = self.get_workflow(workflow.id)
return workflow_api
else: