load the workflow_spec_service from app to avoid frequent file scans.

This commit is contained in:
Dan 2022-02-07 12:30:20 -05:00
parent e4f7e14a4d
commit abc17a8aff
4 changed files with 27 additions and 22 deletions

View File

@ -57,7 +57,7 @@ from crc.api import admin
from crc.services.workflow_service import WorkflowService
from crc.services.workflow_spec_service import WorkflowSpecService
connexion_app.add_api('api.yml', base_path='/v1.0')
workflow_spec_service = WorkflowSpecService()
# needed function to avoid circular import
def process_waiting_tasks():

View File

@ -1,6 +1,6 @@
import enum
from marshmallow import EXCLUDE
from marshmallow import EXCLUDE, post_load
from sqlalchemy import func
from crc import db, ma
@ -19,12 +19,15 @@ class WorkflowSpecCategorySchema(ma.Schema):
model = WorkflowSpecCategory
fields = ["id", "display_name", "display_order", "admin"]
@post_load
def make_cat(self, data, **kwargs):
return WorkflowSpecCategory(**data)
class WorkflowSpecInfo(object):
def __init__(self, id, display_name, description, category_name,
display_order, is_master_spec,
standalone, library, primary_file_name, primary_process_id, is_review,
libraries):
def __init__(self, id, display_name, description, is_master_spec,
standalone, library, primary_file_name, primary_process_id,
libraries, category_name=None, display_order=0, is_review=False):
self.id = id # Sting unique id
self.display_name = display_name
self.description = description
@ -45,9 +48,12 @@ class WorkflowSpecInfoSchema(ma.Schema):
model = WorkflowSpecInfo
fields = ["id", "display_name", "description", "category_id", "is_master_spec,",
"standalone", "library", "primary_file_name", "primary_process_id", "is_review",
"libraries"]
"libraries", "category_name", "display_order", "is_master_spec", "is_review"]
unknown = EXCLUDE
@post_load
def make_spec(self, data, **kwargs):
return WorkflowSpecInfo(**data)
class WorkflowState(enum.Enum):
hidden = "hidden"

View File

@ -1,5 +1,6 @@
{
"id": 2,
"admin": false,
"display_order": 1
"display_order": 1,
"display_name": "Category Number Two"
}

View File

@ -7,7 +7,7 @@ from tests.base_test import BaseTest
from crc.models.workflow import WorkflowSpecInfo, WorkflowSpecCategory
from crc.services.file_system_service import FileSystemService
from crc.services.spec_file_service import SpecFileService
from crc import db, app, WorkflowSpecService
from crc import db, app, workflow_spec_service
class TestWorkflowSync(BaseTest):
@ -34,25 +34,23 @@ class TestWorkflowSync(BaseTest):
self.load_test_spec('email', category_id=c1.id, library=True)
def test_from_file_system_blank_slate(self):
service = WorkflowSpecService()
self.assertEquals(0, len(service.get_categories()))
self.assertEquals(0, len(service.get_specs()))
self.assertEquals(0, len(workflow_spec_service.get_categories()))
self.assertEquals(0, len(workflow_spec_service.get_specs()))
self.copy_files_to_file_system()
self.assertEquals(2, len(service.get_categories()))
self.assertEquals(5, len(service.get_specs()))
self.assertEquals(1, len(service.get_category('Category Number One').workflows))
self.assertEquals(2, len(service.get_category('Category Number Two').workflows))
self.assertIsNotNone(service.master_spec)
self.assertEquals(1, len(service.get_libraries()))
self.assertEquals(1, len(service.master_spec.libraries))
self.assertEquals(2, len(workflow_spec_service.get_categories()))
self.assertEquals(5, len(workflow_spec_service.get_specs()))
self.assertEquals(1, len(workflow_spec_service.get_category('Category Number One').workflows))
self.assertEquals(2, len(workflow_spec_service.get_category('Category Number Two').workflows))
self.assertIsNotNone(workflow_spec_service.master_spec)
self.assertEquals(1, len(workflow_spec_service.get_libraries()))
self.assertEquals(1, len(workflow_spec_service.master_spec.libraries))
def test_delete_category_and_workflows(self):
self.copy_files_to_file_system()
service = WorkflowSpecService()
cat_path = SpecFileService().category_path('Category Number One')
shutil.rmtree(cat_path) # Remove the path, as if from a git pull and the path was removed.
self.assertEquals(2, len(service.get_categories()))
self.assertEquals(4, len(service.get_specs()))
self.assertEquals(3, len(workflow_spec_service.get_categories()))
self.assertEquals(4, len(workflow_spec_service.get_specs()))