This commit is contained in:
jasquat 2022-11-15 15:06:22 -05:00
parent 3a1a25eba9
commit 74accb33ce
5 changed files with 38 additions and 30 deletions

View File

@ -36,8 +36,9 @@ class SpecReferenceCache(SpiffworkflowBaseDBModel):
"""A cache of information about all the Processes and Decisions defined in all files.""" """A cache of information about all the Processes and Decisions defined in all files."""
__tablename__ = "spec_reference_cache" __tablename__ = "spec_reference_cache"
__table_args__ = (UniqueConstraint('identifier', 'type', name='_identifier_type_unique'), __table_args__ = (
) UniqueConstraint("identifier", "type", name="_identifier_type_unique"),
)
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
identifier = db.Column(db.String(255), index=True) identifier = db.Column(db.String(255), index=True)
display_name = db.Column(db.String(255), index=True) display_name = db.Column(db.String(255), index=True)

View File

@ -5,6 +5,7 @@ from flask_bpmn.models.db import db
from spiffworkflow_backend.services.process_model_service import ProcessModelService from spiffworkflow_backend.services.process_model_service import ProcessModelService
from spiffworkflow_backend.services.spec_file_service import SpecFileService from spiffworkflow_backend.services.spec_file_service import SpecFileService
class DataSetupService: class DataSetupService:
"""DataSetupService.""" """DataSetupService."""
@ -15,10 +16,11 @@ class DataSetupService:
@classmethod @classmethod
def save_all_process_models(cls) -> list: def save_all_process_models(cls) -> list:
"""Build a cache of all processes, messages, correlation keys, and start events that """Build a cache of all processes, messages, correlation keys, and start events.
exist within processes located on the file system, so we can quickly reference them
from the database. """
These all exist within processes located on the file system, so we can quickly reference them
from the database.
"""
# Clear out all of the cached data. # Clear out all of the cached data.
SpecFileService.clear_caches() SpecFileService.clear_caches()
@ -26,9 +28,7 @@ class DataSetupService:
failing_process_models = [] failing_process_models = []
process_models = ProcessModelService().get_process_models() process_models = ProcessModelService().get_process_models()
for process_model in process_models: for process_model in process_models:
current_app.logger.debug( current_app.logger.debug(f"Process Model: {process_model.display_name}")
f"Process Model: {process_model.display_name}"
)
try: try:
refs = SpecFileService.get_references_for_process(process_model) refs = SpecFileService.get_references_for_process(process_model)
@ -37,11 +37,11 @@ class DataSetupService:
SpecFileService.update_caches(ref) SpecFileService.update_caches(ref)
except Exception as ex: except Exception as ex:
failing_process_models.append( failing_process_models.append(
( (
f"{ref.process_model_id}/{ref.file_name}", f"{ref.process_model_id}/{ref.file_name}",
str(ex), str(ex),
)
) )
)
except Exception as ex2: except Exception as ex2:
failing_process_models.append( failing_process_models.append(
( (
@ -50,6 +50,8 @@ class DataSetupService:
) )
) )
current_app.logger.debug("DataSetupService.save_all_process_models() end") current_app.logger.debug(
"DataSetupService.save_all_process_models() end"
)
db.session.commit() db.session.commit()
return failing_process_models return failing_process_models

View File

@ -684,9 +684,11 @@ class ProcessInstanceProcessor:
bpmn_process_identifiers = refs.keys() bpmn_process_identifiers = refs.keys()
if bpmn_process_identifier in bpmn_process_identifiers: if bpmn_process_identifier in bpmn_process_identifiers:
SpecFileService.update_process_cache(refs[bpmn_process_identifier]) SpecFileService.update_process_cache(refs[bpmn_process_identifier])
return FileSystemService.full_path_to_process_model_file(process_model) return FileSystemService.full_path_to_process_model_file(
except Exception as e: process_model
current_app.logger.warning('Failed to parse process ', process_model.id) )
except Exception:
current_app.logger.warning("Failed to parse process ", process_model.id)
return None return None
@staticmethod @staticmethod

View File

@ -156,7 +156,9 @@ class SpecFileService(FileSystemService):
file = SpecFileService.to_file_object(file_name, full_file_path) file = SpecFileService.to_file_object(file_name, full_file_path)
references = SpecFileService.get_references_for_file(file, process_model_info) references = SpecFileService.get_references_for_file(file, process_model_info)
primary_process_ref = next((ref for ref in references if ref.is_primary and ref.is_executable), None) primary_process_ref = next(
(ref for ref in references if ref.is_primary and ref.is_executable), None
)
for ref in references: for ref in references:
# If no valid primary process is defined, default to the first process in the # If no valid primary process is defined, default to the first process in the
@ -226,14 +228,16 @@ class SpecFileService(FileSystemService):
# fixme: Place all the caching stuff in a different service. # fixme: Place all the caching stuff in a different service.
@staticmethod @staticmethod
def update_caches(ref): def update_caches(ref: SpecReference) -> None:
"""Update_caches."""
SpecFileService.update_process_cache(ref) SpecFileService.update_process_cache(ref)
SpecFileService.update_message_cache(ref) SpecFileService.update_message_cache(ref)
SpecFileService.update_message_trigger_cache(ref) SpecFileService.update_message_trigger_cache(ref)
SpecFileService.update_correlation_cache(ref) SpecFileService.update_correlation_cache(ref)
@staticmethod @staticmethod
def clear_caches(): def clear_caches() -> None:
"""Clear_caches."""
db.session.query(SpecReferenceCache).delete() db.session.query(SpecReferenceCache).delete()
db.session.query(MessageCorrelationPropertyModel).delete() db.session.query(MessageCorrelationPropertyModel).delete()
db.session.query(MessageTriggerableProcessModel).delete() db.session.query(MessageTriggerableProcessModel).delete()
@ -242,10 +246,11 @@ class SpecFileService(FileSystemService):
@staticmethod @staticmethod
def update_process_cache(ref: SpecReference) -> None: def update_process_cache(ref: SpecReference) -> None:
"""Update_process_cache.""" """Update_process_cache."""
process_id_lookup = SpecReferenceCache.query.\ process_id_lookup = (
filter_by(identifier=ref.identifier).\ SpecReferenceCache.query.filter_by(identifier=ref.identifier)
filter_by(type=ref.type).\ .filter_by(type=ref.type)
first() .first()
)
if process_id_lookup is None: if process_id_lookup is None:
process_id_lookup = SpecReferenceCache.from_spec_reference(ref) process_id_lookup = SpecReferenceCache.from_spec_reference(ref)
db.session.add(process_id_lookup) db.session.add(process_id_lookup)
@ -299,12 +304,10 @@ class SpecFileService(FileSystemService):
).first() ).first()
) )
if message_triggerable_process_model is None: if message_triggerable_process_model is None:
message_triggerable_process_model = ( message_triggerable_process_model = MessageTriggerableProcessModel(
MessageTriggerableProcessModel( message_model_id=message_model.id,
message_model_id=message_model.id, process_model_identifier=ref.process_model_id,
process_model_identifier=ref.process_model_id, process_group_identifier="process_group_identifier",
process_group_identifier="process_group_identifier"
)
) )
db.session.add(message_triggerable_process_model) db.session.add(message_triggerable_process_model)
db.session.commit() db.session.commit()

View File

@ -97,7 +97,7 @@ class TestSpecFileService(BaseTest):
process_id_lookup = SpecReferenceCache( process_id_lookup = SpecReferenceCache(
identifier=bpmn_process_identifier, identifier=bpmn_process_identifier,
relative_path=self.call_activity_nested_relative_file_path, relative_path=self.call_activity_nested_relative_file_path,
type='process' type="process",
) )
db.session.add(process_id_lookup) db.session.add(process_id_lookup)
db.session.commit() db.session.commit()