From b63ee8159e1e077a9604bc34e14d68e15c7207e0 Mon Sep 17 00:00:00 2001 From: Dan Funk Date: Thu, 14 May 2020 17:13:47 -0400 Subject: [PATCH] We now only return the ready user tasks, not all tasks, and even then the ready user tasks don't come back with the forms and details, just the bare minimum. Speeds things up considerably, and most of this information wasn't used anyway. --- crc/api/workflow.py | 4 ++-- crc/services/workflow_service.py | 6 ++++++ example_data.py | 11 +++-------- tests/test_tasks_api.py | 17 +++-------------- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/crc/api/workflow.py b/crc/api/workflow.py index 49cd2fc1..d1ad6d72 100644 --- a/crc/api/workflow.py +++ b/crc/api/workflow.py @@ -84,8 +84,8 @@ def delete_workflow_specification(spec_id): def __get_workflow_api_model(processor: WorkflowProcessor): - spiff_tasks = processor.get_all_user_tasks() - user_tasks = [WorkflowService.spiff_task_to_api_task(t, add_docs_and_forms=True) for t in spiff_tasks] + spiff_tasks = processor.get_ready_user_tasks() + user_tasks = [WorkflowService.spiff_task_to_api_task(t, add_docs_and_forms=False) for t in spiff_tasks] workflow_api = WorkflowApi( id=processor.get_workflow_id(), status=processor.get_status(), diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index bc8f47a5..f5d39ca9 100644 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -118,8 +118,14 @@ class WorkflowService(object): for field in task.form.fields: WorkflowService.process_options(spiff_task, field) task.documentation = WorkflowService._process_documentation(spiff_task) + + # All ready tasks should have a valid name, and this can be computed for + # some tasks, particularly multi-instance tasks that all have the same spec + # but need different labels. + if spiff_task.state == SpiffTask.READY: task.props = WorkflowService._process_properties(spiff_task, props) + return task @staticmethod diff --git a/example_data.py b/example_data.py index 7cf8246b..22e6f95b 100644 --- a/example_data.py +++ b/example_data.py @@ -1,16 +1,11 @@ -import datetime +import glob import glob import os -import xml.etree.ElementTree as ElementTree from crc import app, db, session -from crc.models.file import FileType, FileModel, FileDataModel, CONTENT_TYPES -from crc.models.study import StudyModel -from crc.models.user import UserModel +from crc.models.file import CONTENT_TYPES from crc.models.workflow import WorkflowSpecModel, WorkflowSpecCategoryModel from crc.services.file_service import FileService -from crc.services.workflow_processor import WorkflowProcessor -from crc.models.protocol_builder import ProtocolBuilderStatus class ExampleDataLoader: @@ -19,7 +14,7 @@ class ExampleDataLoader: session.flush() # Clear out any transactions before deleting it all to avoid spurious errors. for table in reversed(db.metadata.sorted_tables): session.execute(table.delete()) - session.flush() + session.flush() def load_all(self): diff --git a/tests/test_tasks_api.py b/tests/test_tasks_api.py index 76342012..53b48bd0 100644 --- a/tests/test_tasks_api.py +++ b/tests/test_tasks_api.py @@ -101,7 +101,7 @@ class TestTasksApi(BaseTest): # get the first form in the two form workflow. workflow_api = self.get_workflow_api(workflow) self.assertEqual('two_forms', workflow_api.workflow_spec_id) - self.assertEqual(2, len(workflow_api.user_tasks)) + self.assertEqual(1, len(workflow_api.user_tasks)) self.assertIsNotNone(workflow_api.next_task['form']) self.assertEqual("UserTask", workflow_api.next_task['type']) self.assertEqual("StepOne", workflow_api.next_task['name']) @@ -334,7 +334,7 @@ class TestTasksApi(BaseTest): workflow = self.create_workflow('subprocess') tasks = self.get_workflow_api(workflow).user_tasks - self.assertEquals(2, len(tasks)) + self.assertEquals(1, len(tasks)) self.assertEquals("UserTask", tasks[0].type) self.assertEquals("Activity_A", tasks[0].name) self.assertEquals("My Sub Process", tasks[0].process_name) @@ -412,19 +412,8 @@ class TestTasksApi(BaseTest): for i in random.sample(range(9), 9): self.complete_form(workflow, tasks[i], {"investigator":{"email": "dhf8r@virginia.edu"}}) - tasks = self.get_workflow_api(workflow).user_tasks + #tasks = self.get_workflow_api(workflow).user_tasks workflow = self.get_workflow_api(workflow) self.assertEquals(WorkflowStatus.complete, workflow.status) - # def test_parent_task_set_on_tasks(self): - # self.load_example_data() - # workflow = self.create_workflow('exclusive_gateway') - # - # # Start the workflow. - # workflow = self.get_workflow_api(workflow) - # self.assertEquals(None, workflow.previous_task) - # self.complete_form(workflow, workflow.next_task, {"has_bananas": True}) - # workflow = self.get_workflow_api(workflow) - # self.assertEquals('Task_Num_Bananas', workflow.next_task['name']) - # self.assertEquals('has_bananas', workflow.previous_task['name'])