示例#1
0
 /**
  * Start or continue the process with the help of given WorkflowEngine and optionally with given WorkflowMessage
  *
  * @param WorkflowEngine $workflowEngine
  * @param WorkflowMessage $workflowMessage
  * @return void
  */
 public function perform(WorkflowEngine $workflowEngine, WorkflowMessage $workflowMessage = null)
 {
     if (is_null($workflowMessage)) {
         $this->startWithoutMessage($workflowEngine);
         return;
     }
     $taskListEntry = $this->taskList->getNextNotStartedTaskListEntry();
     if ($taskListEntry) {
         $this->recordThat(TaskEntryMarkedAsRunning::at($taskListEntry->taskListPosition()));
         if (!$this->isCorrectMessageFor($taskListEntry->task(), $workflowMessage)) {
             $this->receiveMessage(LogMessage::logWrongMessageReceivedFor($taskListEntry->task(), $taskListEntry->taskListPosition(), $workflowMessage), $workflowEngine);
             return;
         }
         $this->performTask($taskListEntry->task(), $taskListEntry->taskListPosition(), $workflowEngine, $workflowMessage);
         return;
     }
 }
示例#2
0
 /**
  * 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);
 }
示例#3
0
 /**
  * @test
  */
 public function it_logs_wrong_message_received_for_task_as_error()
 {
     $wfMessage = $this->getTestWorkflowMessage();
     $task = CollectData::from('crm', UserDictionary::prototype());
     $logMessage = LogMessage::logWrongMessageReceivedFor($task, $wfMessage->processTaskListPosition(), $wfMessage);
     $this->assertTrue($logMessage->isError());
     $this->assertEquals(415, $logMessage->msgCode());
     $this->assertEquals($wfMessage->processTaskListPosition()->taskListId()->nodeName()->toString(), $logMessage->origin());
     $this->assertTrue($wfMessage->processTaskListPosition()->equals($logMessage->processTaskListPosition()));
     $this->assertTrue(isset($logMessage->msgParams()['task_class']));
     $this->assertTrue(isset($logMessage->msgParams()['task_as_json']));
     $this->assertTrue(isset($logMessage->msgParams()['task_list_position']));
     $this->assertTrue(isset($logMessage->msgParams()['process_id']));
     $this->assertTrue(isset($logMessage->msgParams()['message_name']));
     $this->assertEquals(NodeName::defaultName()->toString(), $logMessage->target());
     $this->assertEquals($wfMessage->processTaskListPosition()->taskListId()->processId()->toString(), $logMessage->msgParams()['process_id']);
     $this->assertEquals($wfMessage->processTaskListPosition()->position(), $logMessage->msgParams()['task_list_position']);
     $this->assertEquals(get_class($task), $logMessage->msgParams()['task_class']);
     $this->assertEquals(json_encode($task->getArrayCopy()), $logMessage->msgParams()['task_as_json']);
     $this->assertEquals($wfMessage->messageName(), $logMessage->msgParams()['message_name']);
 }
示例#4
0
 /**
  * @param ManipulatePayload $task
  * @param TaskListPosition $taskListPosition
  * @param WorkflowEngine $workflowEngine
  * @param WorkflowMessage $previousMessage
  */
 protected function performManipulatePayload(ManipulatePayload $task, TaskListPosition $taskListPosition, WorkflowEngine $workflowEngine, WorkflowMessage $previousMessage)
 {
     if (!MessageNameUtils::isProcessingEvent($previousMessage->messageName())) {
         $this->receiveMessage(LogMessage::logWrongMessageReceivedFor($task, $taskListPosition, $previousMessage), $workflowEngine);
         return;
     }
     $payload = $previousMessage->payload();
     try {
         $task->performManipulationOn($payload);
     } catch (\Exception $ex) {
         $this->receiveMessage(LogMessage::logException($ex, $taskListPosition), $workflowEngine);
         return;
     }
     $newEvent = $previousMessage->prepareDataProcessing($taskListPosition, $this->taskList->taskListId()->nodeName())->answerWithDataProcessingCompleted();
     $this->receiveMessage($newEvent, $workflowEngine);
 }
示例#5
0
 /**
  * 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);
 }