diff --git a/src/spiffworkflow_backend/services/process_instance_processor.py b/src/spiffworkflow_backend/services/process_instance_processor.py index 452e8ca2..5ce14990 100644 --- a/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/src/spiffworkflow_backend/services/process_instance_processor.py @@ -719,52 +719,59 @@ class ProcessInstanceProcessor: """Queue_waiting_receive_messages.""" waiting_tasks = self.get_all_waiting_tasks() for waiting_task in waiting_tasks: - if waiting_task.task_spec.__class__.__name__ in [ + # if it's not something that can wait for a message, skip it + if waiting_task.task_spec.__class__.__name__ not in [ "IntermediateCatchEvent", "ReceiveTask", ]: - message_model = MessageModel.query.filter_by( - name=waiting_task.task_spec.event_definition.name - ).first() - if message_model is None: - raise ApiError( - "invalid_message_name", - f"Invalid message name: {waiting_task.task_spec.event_definition.name}.", - ) + continue - message_instance = MessageInstanceModel( - process_instance_id=self.process_instance_model.id, - message_type="receive", - message_model_id=message_model.id, + # timer events are not related to messaging, so ignore them for these purposes + if waiting_task.task_spec.event_definition.__class__.__name__ in [ + "TimerEventDefinition", + ]: + continue + + message_model = MessageModel.query.filter_by( + name=waiting_task.task_spec.event_definition.name + ).first() + if message_model is None: + raise ApiError( + "invalid_message_name", + f"Invalid message name: {waiting_task.task_spec.event_definition.name}.", ) - db.session.add(message_instance) - for ( - spiff_correlation_property - ) in waiting_task.task_spec.event_definition.correlation_properties: - # NOTE: we may have to cycle through keys here - # not sure yet if it's valid for a property to be associated with multiple keys - correlation_key_name = spiff_correlation_property.correlation_keys[ - 0 - ] - message_correlation = ( - MessageCorrelationModel.query.filter_by( - process_instance_id=self.process_instance_model.id, - name=correlation_key_name, - ) - .join(MessageCorrelationPropertyModel) - .filter_by(identifier=spiff_correlation_property.name) - .first() - ) - message_correlation_message_instance = ( - MessageCorrelationMessageInstanceModel( - message_instance_id=message_instance.id, - message_correlation_id=message_correlation.id, - ) - ) - db.session.add(message_correlation_message_instance) + message_instance = MessageInstanceModel( + process_instance_id=self.process_instance_model.id, + message_type="receive", + message_model_id=message_model.id, + ) + db.session.add(message_instance) - db.session.commit() + for ( + spiff_correlation_property + ) in waiting_task.task_spec.event_definition.correlation_properties: + # NOTE: we may have to cycle through keys here + # not sure yet if it's valid for a property to be associated with multiple keys + correlation_key_name = spiff_correlation_property.correlation_keys[0] + message_correlation = ( + MessageCorrelationModel.query.filter_by( + process_instance_id=self.process_instance_model.id, + name=correlation_key_name, + ) + .join(MessageCorrelationPropertyModel) + .filter_by(identifier=spiff_correlation_property.name) + .first() + ) + message_correlation_message_instance = ( + MessageCorrelationMessageInstanceModel( + message_instance_id=message_instance.id, + message_correlation_id=message_correlation.id, + ) + ) + db.session.add(message_correlation_message_instance) + + db.session.commit() def do_engine_steps(self, exit_at: None = None, save: bool = False) -> None: """Do_engine_steps.""" diff --git a/tests/data/timer_intermediate_catch_event/timer_intermediate_catch_event.bpmn b/tests/data/timer_intermediate_catch_event/timer_intermediate_catch_event.bpmn new file mode 100644 index 00000000..28312f57 --- /dev/null +++ b/tests/data/timer_intermediate_catch_event/timer_intermediate_catch_event.bpmn @@ -0,0 +1,44 @@ + + + + + Flow_109wuuc + + + + Flow_0cy1fiy + + + + Flow_109wuuc + Flow_0cy1fiy + + timedelta(seconds=30) + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/spiffworkflow_backend/unit/test_message_service.py b/tests/spiffworkflow_backend/unit/test_message_service.py index fe72c926..38079c96 100644 --- a/tests/spiffworkflow_backend/unit/test_message_service.py +++ b/tests/spiffworkflow_backend/unit/test_message_service.py @@ -188,9 +188,13 @@ class TestMessageService(BaseTest): process_instance_result = ProcessInstanceModel.query.all() assert len(process_instance_result) == 3 - process_instance_receiver_one = ProcessInstanceModel.query.filter_by(process_model_identifier='message_receiver_one').first() + process_instance_receiver_one = ProcessInstanceModel.query.filter_by( + process_model_identifier="message_receiver_one" + ).first() assert process_instance_receiver_one is not None - process_instance_receiver_two = ProcessInstanceModel.query.filter_by(process_model_identifier='message_receiver_two').first() + process_instance_receiver_two = ProcessInstanceModel.query.filter_by( + process_model_identifier="message_receiver_two" + ).first() assert process_instance_receiver_two is not None # just make sure it's a different process instance diff --git a/tests/spiffworkflow_backend/unit/test_various_bpmn_constructs.py b/tests/spiffworkflow_backend/unit/test_various_bpmn_constructs.py new file mode 100644 index 00000000..f282ed94 --- /dev/null +++ b/tests/spiffworkflow_backend/unit/test_various_bpmn_constructs.py @@ -0,0 +1,24 @@ +"""Test_various_bpmn_constructs.""" +from flask.app import Flask +from spiffworkflow_backend.services.process_instance_processor import ProcessInstanceProcessor +from tests.spiffworkflow_backend.helpers.base_test import BaseTest +from tests.spiffworkflow_backend.helpers.test_data import load_test_spec + + +class TestVariousBpmnConstructs(BaseTest): + """TestVariousBpmnConstructs.""" + + def test_running_process_with_timer_intermediate_catch_event( + self, app: Flask, with_db_and_bpmn_file_cleanup: None + ) -> None: + """Test_running_process_with_timer_intermediate_catch_event.""" + process_model = load_test_spec( + "timers_intermediate_catch_event", + process_model_source_directory="timer_intermediate_catch_event", + ) + + process_instance = self.create_process_instance_from_process_model( + process_model + ) + processor = ProcessInstanceProcessor(process_instance) + processor.do_engine_steps(save=True)