/**
  * @param TaskId $taskId
  * @param TaskType $taskType
  * @param MessageHandler $messageHandler
  * @param Prototype $processingType
  * @param ProcessingMetadata $metadata
  * @return TaskWasSetUp
  */
 public static function with(TaskId $taskId, TaskType $taskType, MessageHandler $messageHandler, Prototype $processingType, ProcessingMetadata $metadata)
 {
     $event = self::occur($taskId->toString(), ['task_type' => $taskType->toString(), 'message_handler_id' => $messageHandler->messageHandlerId()->toString(), 'processing_type' => $processingType->of(), 'task_metadata' => $metadata->toArray()]);
     $event->taskId = $taskId;
     $event->taskType = $taskType;
     $event->messageHandlerId = $messageHandler->messageHandlerId();
     $event->processingType = $processingType;
     $event->taskMetadata = $metadata;
     return $event;
 }
示例#2
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);
 }
 /**
  * @param MessageHandlerId $messageHandlerId
  * @param $messageHandlerName
  * @param MessageHandler\HandlerType $handlerType
  * @param MessageHandler\DataDirection $dataDirection
  * @param MessageHandler\ProcessingTypes $supportedProcessingTypes
  * @param ProcessingMetadata $processingMetadata
  * @param string $metadataRiotTag
  * @param string $icon
  * @param string $iconType
  * @param null|Prototype $preferredProcessingType
  * @param null|MessageHandler\ProcessingId $processingId
  * @param array $additionalData
  * @return MessageHandler
  */
 public function installMessageHandler(MessageHandlerId $messageHandlerId, $messageHandlerName, HandlerType $handlerType, DataDirection $dataDirection, ProcessingTypes $supportedProcessingTypes, ProcessingMetadata $processingMetadata, $metadataRiotTag, $icon, $iconType, Prototype $preferredProcessingType = null, ProcessingId $processingId = null, array $additionalData = [])
 {
     return MessageHandler::fromDefinition($messageHandlerId, $messageHandlerName, $this->nodeName(), $handlerType, $dataDirection, $supportedProcessingTypes, $processingMetadata, $metadataRiotTag, $icon, $iconType, $preferredProcessingType, $processingId, $additionalData);
 }
 /**
  * @param MessageHandler $messageHandler
  * @param Message $message
  * @return MessageIsNotManageable
  */
 public static function byMessageHandler(MessageHandler $messageHandler, Message $message)
 {
     $message = sprintf("Message %s -> %s is not manageable by message handler %s: %s", $message->messageType()->toString(), $message->processingType()->typeDescription()->label(), $messageHandler->name(), $messageHandler->lastValidationError());
     return new self($message);
 }
示例#5
0
 /**
  * @param bool $singleItemMode
  * @return MessageHandler
  */
 protected function getArticleImporterMessageHandler($singleItemMode = false)
 {
     $supportedProcessingType = $singleItemMode ? Article::prototype() : ArticleCollection::prototype();
     return MessageHandler::fromDefinition(MessageHandlerId::generate(), 'Article Importer', NodeName::defaultName(), MessageHandler\HandlerType::connector(), MessageHandler\DataDirection::target(), MessageHandler\ProcessingTypes::support([$supportedProcessingType]), ProcessingMetadata::fromArray(['chunk_support' => true]), 'sqlconnector-pm-metadata', 'glyphicon-hdd', 'glyphicon');
 }
 /**
  * @param $dataDirection
  * @param null|string $handlerType
  * @param null|array $metadata
  * @return MessageHandler
  */
 private function getMessageHandler($dataDirection, $handlerType = null, array $metadata = null)
 {
     if (!is_null($handlerType)) {
         $handlerType = MessageHandler\HandlerType::fromString($handlerType);
     } else {
         $handlerType = MessageHandler\HandlerType::connector();
     }
     if (!is_null($metadata)) {
         $metadata = ProcessingMetadata::fromArray($metadata);
     } else {
         $metadata = ProcessingMetadata::noData();
     }
     return MessageHandler::fromDefinition(MessageHandlerId::generate(), 'Article Export', NodeName::defaultName(), $handlerType, MessageHandler\DataDirection::fromString($dataDirection), MessageHandler\ProcessingTypes::support([ArticleCollection::prototype(), Article::prototype()]), $metadata, 'sqlconnector-pm-metadata', 'glyphicon-hdd', 'glyphicon', Article::prototype(), MessageHandler\ProcessingId::fromString('sqlconnector:::example'));
 }
 /**
  * @param MessageHandler $messageHandler
  * @return array
  */
 private function determineAllowedMessages(MessageHandler $messageHandler)
 {
     $allowedMessages = [];
     if ($messageHandler->dataDirection()->isSource()) {
         $allowedMessages[] = MessageNameUtils::COLLECT_DATA;
     }
     if ($messageHandler->dataDirection()->isTarget()) {
         $allowedMessages[] = MessageNameUtils::PROCESS_DATA;
     }
     if ($messageHandler->handlerType()->isCallback()) {
         $allowedMessages[] = MessageNameUtils::DATA_COLLECTED;
         $allowedMessages[] = MessageNameUtils::DATA_PROCESSED;
     }
     return $allowedMessages;
 }