/** * @param WorkflowEngine $workflowEngine */ protected function startWithoutMessage(WorkflowEngine $workflowEngine) { $taskListEntry = $this->taskList->getNextNotStartedTaskListEntry(); if ($taskListEntry) { $this->recordThat(TaskEntryMarkedAsRunning::at($taskListEntry->taskListPosition())); $task = $taskListEntry->task(); if (!$task instanceof CollectData && !$task instanceof RunSubProcess) { $this->receiveMessage(LogMessage::logNoMessageReceivedFor($task, $taskListEntry->taskListPosition()), $workflowEngine); return; } $this->performTask($task, $taskListEntry->taskListPosition(), $workflowEngine); } }
/** * @test */ public function it_logs_no_message_received_for_task_as_error() { $wfMessage = $this->getTestWorkflowMessage(); $task = CollectData::from('crm', UserDictionary::prototype()); $message = LogMessage::logNoMessageReceivedFor($task, $wfMessage->processTaskListPosition()); $this->assertTrue($message->isError()); $this->assertEquals(412, $message->msgCode()); $this->assertEquals($wfMessage->processTaskListPosition()->taskListId()->nodeName(), $message->origin()); $this->assertTrue($wfMessage->processTaskListPosition()->equals($message->processTaskListPosition())); $this->assertTrue(isset($message->msgParams()['task_class'])); $this->assertTrue(isset($message->msgParams()['task_as_json'])); $this->assertTrue(isset($message->msgParams()['task_list_position'])); $this->assertTrue(isset($message->msgParams()['process_id'])); $this->assertEquals($wfMessage->processTaskListPosition()->taskListId()->processId()->toString(), $message->msgParams()['process_id']); $this->assertEquals($wfMessage->processTaskListPosition()->position(), $message->msgParams()['task_list_position']); $this->assertEquals(get_class($task), $message->msgParams()['task_class']); $this->assertEquals(json_encode($task->getArrayCopy()), $message->msgParams()['task_as_json']); $this->assertEquals(NodeName::defaultName()->toString(), $message->target()); }
/** * Start or continue the process with the help of given WorkflowEngine and optionally with given WorkflowMessage * * @param WorkflowEngine $workflowEngine * @param WorkflowMessage $workflowMessage * @throws \RuntimeException * @throws \BadMethodCallException * @return void */ public function perform(WorkflowEngine $workflowEngine, WorkflowMessage $workflowMessage = null) { $taskListEntry = $this->taskList->getNextNotStartedTaskListEntry(); if (is_null($taskListEntry)) { throw new \RuntimeException('ForEachProcess::perform was called but there are no tasks configured!'); } if (is_null($workflowMessage)) { $this->recordThat(TaskEntryMarkedAsRunning::at($taskListEntry->taskListPosition())); $this->receiveMessage(LogMessage::logNoMessageReceivedFor($taskListEntry->task(), $taskListEntry->taskListPosition()), $workflowEngine); return; } $workflowMessage = $workflowMessage->reconnectToProcessTask($taskListEntry->taskListPosition()); if (count($this->taskList->getAllTaskListEntries()) > 1) { $this->recordThat(TaskEntryMarkedAsRunning::at($taskListEntry->taskListPosition())); $this->receiveMessage(LogMessage::logErrorMsg('The ForEachProcess can only handle a single RunSubProcess task but there are more tasks configured', $workflowMessage), $workflowEngine); return; } if (!$taskListEntry->task() instanceof RunSubProcess) { $this->recordThat(TaskEntryMarkedAsRunning::at($taskListEntry->taskListPosition())); $this->receiveMessage(LogMessage::logErrorMsg(sprintf('The ForEachProcess can only handle a RunSubProcess task but there is a %s task configured', get_class($taskListEntry->task())), $workflowMessage), $workflowEngine); return; } if (!MessageNameUtils::isProcessingEvent($workflowMessage->messageName())) { $this->recordThat(TaskEntryMarkedAsRunning::at($taskListEntry->taskListPosition())); $this->receiveMessage(LogMessage::logWrongMessageReceivedFor($taskListEntry->task(), $taskListEntry->taskListPosition(), $workflowMessage), $workflowEngine); return; } $collection = $workflowMessage->payload()->toType(); if (!$collection instanceof CollectionType) { $this->receiveMessage(LogMessage::logErrorMsg(sprintf('The ForEachProcess requires a Prooph\\ProcessingType\\CollectionType as payload of the incoming message, but it is a %s type given', $workflowMessage->payload()->getTypeClass()), $workflowMessage), $workflowEngine); return; } $this->startSubProcessForEachItem($collection, $workflowEngine); }
/** * Start or continue the process with the help of given WorkflowEngine and optionally with given WorkflowMessage * * @param WorkflowEngine $workflowEngine * @param WorkflowMessage $workflowMessage * @throws \RuntimeException * @return void */ public function perform(WorkflowEngine $workflowEngine, WorkflowMessage $workflowMessage = null) { $taskListEntry = $this->taskList->getNextNotStartedTaskListEntry(); if (is_null($taskListEntry)) { throw new \RuntimeException('ChunkProcess::perform was called but there are no tasks configured!'); } if (is_null($workflowMessage)) { $this->recordThat(TaskEntryMarkedAsRunning::at($taskListEntry->taskListPosition())); $this->receiveMessage(LogMessage::logNoMessageReceivedFor($taskListEntry->task(), $taskListEntry->taskListPosition()), $workflowEngine); return; } $workflowMessage = $workflowMessage->reconnectToProcessTask($taskListEntry->taskListPosition()); if (count($this->taskList->getAllTaskListEntries()) > 1) { $this->recordThat(TaskEntryMarkedAsRunning::at($taskListEntry->taskListPosition())); $this->logErrorMsg('The ChunkProcess can only handle a single RunSubProcess task but there are more tasks configured', $workflowMessage, $workflowEngine); return; } if (!$taskListEntry->task() instanceof RunSubProcess) { $this->recordThat(TaskEntryMarkedAsRunning::at($taskListEntry->taskListPosition())); $this->logErrorMsg(sprintf('The ChunkProcess can only handle a RunSubProcess task but there is a %s task configured', get_class($taskListEntry->task())), $workflowMessage, $workflowEngine); return; } if (!MessageNameUtils::isProcessingEvent($workflowMessage->messageName())) { $this->recordThat(TaskEntryMarkedAsRunning::at($taskListEntry->taskListPosition())); $this->receiveMessage(LogMessage::logWrongMessageReceivedFor($taskListEntry->task(), $taskListEntry->taskListPosition(), $workflowMessage), $workflowEngine); return; } $collection = $workflowMessage->payload()->toType(); if (!$collection instanceof CollectionType) { $this->logErrorMsg(sprintf('The ChunkProcess requires a Prooph\\ProcessingType\\CollectionType as payload of the incoming message, but it is a %s type given', $workflowMessage->payload()->getTypeClass()), $workflowMessage, $workflowEngine); return; } $metadata = $workflowMessage->metadata(); if (!isset($metadata[self::META_OFFSET])) { $this->logErrorMsg('The ChunkProcess requires a offset key in the message metadata.', $workflowMessage, $workflowEngine); return; } if ((int) $metadata[self::META_OFFSET] !== 0) { $this->logErrorMsg('The ChunkProcess requires that the first chunk starts with a offset of 0.', $workflowMessage, $workflowEngine); return; } if (!isset($metadata[self::META_LIMIT])) { $this->logErrorMsg('The ChunkProcess requires a limit key in the message metadata.', $workflowMessage, $workflowEngine); return; } if ((int) $metadata[self::META_LIMIT] <= 0) { $this->logErrorMsg('The ChunkProcess requires that metadata.limit is greater than 0.', $workflowMessage, $workflowEngine); return; } if (!isset($metadata[self::META_TOTAL_ITEMS])) { $this->logErrorMsg('The ChunkProcess requires a total_items key in the message metadata.', $workflowMessage, $workflowEngine); return; } $this->startSubProcessForEachChunk($workflowMessage, $workflowEngine); }