diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/spec_reference.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/spec_reference.py index 516c0593..92d59ee8 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/spec_reference.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/spec_reference.py @@ -36,8 +36,9 @@ class SpecReferenceCache(SpiffworkflowBaseDBModel): """A cache of information about all the Processes and Decisions defined in all files.""" __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) identifier = db.Column(db.String(255), index=True) display_name = db.Column(db.String(255), index=True) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/data_setup_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/data_setup_service.py index 50aec202..ea0eed96 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/data_setup_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/data_setup_service.py @@ -5,6 +5,7 @@ from flask_bpmn.models.db import db from spiffworkflow_backend.services.process_model_service import ProcessModelService from spiffworkflow_backend.services.spec_file_service import SpecFileService + class DataSetupService: """DataSetupService.""" @@ -15,10 +16,11 @@ class DataSetupService: @classmethod def save_all_process_models(cls) -> list: - """Build a cache of all processes, messages, correlation keys, and start events that - exist within processes located on the file system, so we can quickly reference them - from the database. """ + """Build a cache of all processes, messages, correlation keys, and start events. + 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. SpecFileService.clear_caches() @@ -26,9 +28,7 @@ class DataSetupService: failing_process_models = [] process_models = ProcessModelService().get_process_models() for process_model in process_models: - current_app.logger.debug( - f"Process Model: {process_model.display_name}" - ) + current_app.logger.debug(f"Process Model: {process_model.display_name}") try: refs = SpecFileService.get_references_for_process(process_model) @@ -37,11 +37,11 @@ class DataSetupService: SpecFileService.update_caches(ref) except Exception as ex: failing_process_models.append( - ( - f"{ref.process_model_id}/{ref.file_name}", - str(ex), + ( + f"{ref.process_model_id}/{ref.file_name}", + str(ex), + ) ) - ) except Exception as ex2: 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() return failing_process_models diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py index 2ff6ead9..10913a2e 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -684,9 +684,11 @@ class ProcessInstanceProcessor: bpmn_process_identifiers = refs.keys() if bpmn_process_identifier in bpmn_process_identifiers: SpecFileService.update_process_cache(refs[bpmn_process_identifier]) - return FileSystemService.full_path_to_process_model_file(process_model) - except Exception as e: - current_app.logger.warning('Failed to parse process ', process_model.id) + return FileSystemService.full_path_to_process_model_file( + process_model + ) + except Exception: + current_app.logger.warning("Failed to parse process ", process_model.id) return None @staticmethod diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py index 245c241f..4f160b12 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py @@ -156,7 +156,9 @@ class SpecFileService(FileSystemService): file = SpecFileService.to_file_object(file_name, full_file_path) 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: # 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. @staticmethod - def update_caches(ref): + def update_caches(ref: SpecReference) -> None: + """Update_caches.""" SpecFileService.update_process_cache(ref) SpecFileService.update_message_cache(ref) SpecFileService.update_message_trigger_cache(ref) SpecFileService.update_correlation_cache(ref) @staticmethod - def clear_caches(): + def clear_caches() -> None: + """Clear_caches.""" db.session.query(SpecReferenceCache).delete() db.session.query(MessageCorrelationPropertyModel).delete() db.session.query(MessageTriggerableProcessModel).delete() @@ -242,10 +246,11 @@ class SpecFileService(FileSystemService): @staticmethod def update_process_cache(ref: SpecReference) -> None: """Update_process_cache.""" - process_id_lookup = SpecReferenceCache.query.\ - filter_by(identifier=ref.identifier).\ - filter_by(type=ref.type).\ - first() + process_id_lookup = ( + SpecReferenceCache.query.filter_by(identifier=ref.identifier) + .filter_by(type=ref.type) + .first() + ) if process_id_lookup is None: process_id_lookup = SpecReferenceCache.from_spec_reference(ref) db.session.add(process_id_lookup) @@ -299,12 +304,10 @@ class SpecFileService(FileSystemService): ).first() ) if message_triggerable_process_model is None: - message_triggerable_process_model = ( - MessageTriggerableProcessModel( - message_model_id=message_model.id, - process_model_identifier=ref.process_model_id, - process_group_identifier="process_group_identifier" - ) + message_triggerable_process_model = MessageTriggerableProcessModel( + message_model_id=message_model.id, + process_model_identifier=ref.process_model_id, + process_group_identifier="process_group_identifier", ) db.session.add(message_triggerable_process_model) db.session.commit() diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_spec_file_service.py b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_spec_file_service.py index eb709a5d..d9a7adcb 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_spec_file_service.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_spec_file_service.py @@ -97,7 +97,7 @@ class TestSpecFileService(BaseTest): process_id_lookup = SpecReferenceCache( identifier=bpmn_process_identifier, relative_path=self.call_activity_nested_relative_file_path, - type='process' + type="process", ) db.session.add(process_id_lookup) db.session.commit()