From 0945dde1179a0466adf46223bf176e00d5084840 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Fri, 24 Nov 2023 19:08:05 -0400 Subject: [PATCH 1/2] Throw global signal event --- ProcessMaker/Nayra/Repositories/PersistenceHandler.php | 3 +++ .../Nayra/Repositories/PersistenceTokenTrait.php | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/ProcessMaker/Nayra/Repositories/PersistenceHandler.php b/ProcessMaker/Nayra/Repositories/PersistenceHandler.php index 8a4789b74a..17d5c662be 100644 --- a/ProcessMaker/Nayra/Repositories/PersistenceHandler.php +++ b/ProcessMaker/Nayra/Repositories/PersistenceHandler.php @@ -108,6 +108,9 @@ public function save(array $transaction) case 'start_event_triggered': $this->persistStartEventTriggered($transaction); break; + case 'throw_global_signal_event': + $this->throwGlobalSignalEvent($transaction); + break; case 'event_based_gateway_activated': $this->persistEventBasedGatewayActivated($transaction); break; diff --git a/ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php b/ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php index 25b8cc256d..756129af40 100644 --- a/ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php +++ b/ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php @@ -3,6 +3,7 @@ namespace ProcessMaker\Nayra\Repositories; use Illuminate\Support\Facades\Cache; +use ProcessMaker\Facades\WorkflowManager; use ProcessMaker\Listeners\BpmnSubscriber; use ProcessMaker\Listeners\CommentsSubscriber; use ProcessMaker\Nayra\Bpmn\Events\ActivityActivatedEvent; @@ -298,4 +299,12 @@ public function persistAbout(array $aboutInfo) error_log("Microservice $name version $version is running."); Cache::put(self::$aboutCacheKey, $aboutInfo, 60); } + + public function throwGlobalSignalEvent(array $transaction) + { + $throwElement = $this->deserializer->unserializeEntity($transaction['throw_element']); + $token = $transaction['token'] ? $this->deserializer->unserializeToken($transaction['token']) : null; + $eventDefinition = $throwElement->getEventDefinitions()->item(0); + WorkflowManager::throwSignalEventDefinition($eventDefinition, $token); + } } From 7dde800f5ffe3c38d2a0b2f2260d7139fa6f6fc1 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Fri, 24 Nov 2023 19:34:53 -0400 Subject: [PATCH 2/2] Get IDs of collaborating instances --- .../Nayra/Managers/WorkflowManagerDefault.php | 25 +++++++++++++++---- .../Managers/WorkflowManagerRabbitMq.php | 18 +++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/ProcessMaker/Nayra/Managers/WorkflowManagerDefault.php b/ProcessMaker/Nayra/Managers/WorkflowManagerDefault.php index 7be0689130..4902a9ec37 100644 --- a/ProcessMaker/Nayra/Managers/WorkflowManagerDefault.php +++ b/ProcessMaker/Nayra/Managers/WorkflowManagerDefault.php @@ -32,7 +32,6 @@ use ProcessMaker\Nayra\Contracts\Bpmn\ThrowEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; -use ProcessMaker\Repositories\DefinitionsRepository; class WorkflowManagerDefault implements WorkflowManagerInterface { @@ -265,12 +264,28 @@ public function throwSignalEventDefinition(EventDefinitionInterface $sourceEvent } $excludeProcesses = [$token->getInstance()->getModel()->process_id]; - $excludeRequests = []; - $instances = $token->getInstance()->getProcess()->getEngine()->getExecutionInstances(); + + $excludeRequests = $this->getCollaboratingInstanceIds($token->getInstance()); + ThrowSignalEvent::dispatch($signalRef, $data, $excludeProcesses, $excludeRequests)->onQueue('bpmn'); + } + + /** + * Retrieves IDs of all instances collaborating with the given instance. + * + * This function compiles a list of IDs from execution instances associated + * with the same process as the input instance, including the instance itself. + * + * @param ProcessRequest $instance The instance to find collaborators for. + * @return int[] Array of collaborating instance IDs. + */ + protected function getCollaboratingInstanceIds($instance) + { + $ids = []; + $instances = $instance->getProcess()->getEngine()->getExecutionInstances(); foreach ($instances as $instance) { - $excludeRequests[] = $instance->getId(); + $ids[] = $instance->getId(); } - ThrowSignalEvent::dispatch($signalRef, $data, $excludeProcesses, $excludeRequests)->onQueue('bpmn'); + return $ids; } /** diff --git a/ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php b/ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php index f942a69f92..dbd5ceb7c8 100644 --- a/ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php +++ b/ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php @@ -553,6 +553,24 @@ public function throwSignalEventRequest(ProcessRequest $request, $signalRef, arr ]); } + /** + * Retrieves IDs of all instances collaborating with the given instance. + * + * This function compiles a list of IDs from execution instances associated + * with the same process as the input instance, including the instance itself. + * + * @param ProcessRequest $instance The instance to find collaborators for. + * @return int[] Array of collaborating instance IDs. + */ + protected function getCollaboratingInstanceIds($instance) + { + $ids = ProcessRequest:: + where('process_collaboration_id', $instance->process_collaboration_id) + ->pluck('id') + ->toArray(); + return $ids; + } + /** * Build a state object. *