/**
  * @return Message
  */
 public function startMessage()
 {
     if (is_null($this->startMessage)) {
         $processingType = $this->payload['start_message']['processing_type'];
         $this->startMessage = Message::emulateProcessingWorkflowMessage(MessageType::fromString($this->payload['start_message']['message_type']), $processingType::prototype(), ProcessingMetadata::fromArray($this->payload['start_message']['metadata']));
     }
     return $this->startMessage;
 }
コード例 #2
0
 /**
  * @return Message
  */
 public function startMessage()
 {
     $startMessage = $this->payload['start_message'];
     if (isset($startMessage['metadata'])) {
         $metadata = ProcessingMetadata::fromArray($startMessage['metadata']);
     } else {
         $metadata = ProcessingMetadata::noData();
     }
     $processingType = $startMessage['processing_type'];
     return Message::emulateProcessingWorkflowMessage(MessageType::fromString($startMessage['message_type']), $processingType::prototype(), $metadata);
 }
コード例 #3
0
ファイル: Task.php プロジェクト: prooph/link-process-manager
 /**
  * @return Message
  * @throws \RuntimeException
  */
 public function emulateWorkflowMessage()
 {
     if ($this->type()->isCollectData()) {
         $messageType = MessageType::collectData();
     } elseif ($this->type()->isProcessData()) {
         $messageType = MessageType::processData();
     } else {
         throw new \RuntimeException(sprintf("Can't create a message type for task type %s", $this->type()->toString()));
     }
     return Message::emulateProcessingWorkflowMessage($messageType, $this->processingType(), $this->metadata());
 }
コード例 #4
0
 /**
  * Creates a new task for given message handler and workflow message
  *
  * @param MessageHandler $messageHandler
  * @param ProcessingMetadata $taskMetadata
  * @param Workflow\Message $workflowMessage
  * @return \Prooph\Link\ProcessManager\Model\Task
  * @throws \RuntimeException
  */
 private function scheduleTaskFor(MessageHandler $messageHandler, ProcessingMetadata $taskMetadata, Message $workflowMessage)
 {
     if ($workflowMessage->messageType()->isCollectDataMessage()) {
         $taskType = TaskType::collectData();
     } elseif ($workflowMessage->messageType()->isDataCollectedMessage() || $workflowMessage->messageType()->isDataProcessedMessage()) {
         $taskType = TaskType::processData();
     } else {
         throw new \RuntimeException(sprintf("Failed to determine a task type which can handle a %s message", $workflowMessage->messageType()->toString()));
     }
     if (!empty($messageHandler->processingMetadata()->toArray())) {
         $taskMetadata = $taskMetadata->merge($messageHandler->processingMetadata());
     }
     return Task::setUp($messageHandler, $taskType, $workflowMessage->processingType(), $taskMetadata);
 }
コード例 #5
0
 function provideStartScenarios()
 {
     return [[Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleExporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_LINEAR_MESSAGING], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataProcessed(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleImporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_LINEAR_MESSAGING], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleExporterMessageHandler(true), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_PARALLEL_FOREACH], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataProcessed(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleImporterMessageHandler(true), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_PARALLEL_FOREACH], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100])), $this->getArticleExporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_PARALLEL_CHUNK], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataCollected(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100])), $this->getArticleImporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_PARALLEL_CHUNK]];
 }
コード例 #6
0
 /**
  * @param Message $other
  * @return bool
  */
 public function equals(Message $other)
 {
     return $this->messageType()->equals($other->messageType()) && $this->processingType()->of() === $other->processingType()->of() && $this->processingMetadata()->toArray() === $other->processingMetadata()->toArray();
 }
コード例 #7
0
 /**
  * @param Task $connectedTask
  * @return Message
  * @throws Workflow\Exception\MessageIsNotManageable
  */
 public function emulateAnswerMessage(Task $connectedTask)
 {
     if (!$this->canHandleMessage($connectedTask->emulateWorkflowMessage())) {
         throw MessageIsNotManageable::byMessageHandler($this, $connectedTask->emulateWorkflowMessage());
     }
     if ($connectedTask->type()->isCollectData()) {
         $messageType = MessageType::dataCollected();
     } else {
         $messageType = MessageType::dataProcessed();
     }
     return Message::emulateProcessingWorkflowMessage($messageType, $connectedTask->processingType(), $connectedTask->metadata());
 }
コード例 #8
0
 /**
  * @test
  */
 function it_is_equal_to_a_similar_message()
 {
     $message1 = Message::emulateProcessingWorkflowMessage(MessageType::collectData(), String::prototype(), ProcessingMetadata::fromArray(['meta' => 'data']));
     $message2 = Message::emulateProcessingWorkflowMessage(MessageType::collectData(), String::prototype(), ProcessingMetadata::fromArray(['meta' => 'data']));
     $this->assertTrue($message1->equals($message2));
 }
コード例 #9
0
 function provideMessages()
 {
     return [[Message::emulateProcessingWorkflowMessage(MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::noData())], [Message::emulateProcessingWorkflowMessage(MessageType::dataCollected(), ArticleCollection::prototype(), ProcessingMetadata::noData())], [Message::emulateProcessingWorkflowMessage(MessageType::processData(), ArticleCollection::prototype(), ProcessingMetadata::noData())], [Message::emulateProcessingWorkflowMessage(MessageType::dataProcessed(), ArticleCollection::prototype(), ProcessingMetadata::noData())]];
 }