/**
  * @param WorkflowId $workflowId
  * @param Process $process
  * @param Task $task
  * @return TaskWasAddedToProcess
  */
 public static function record(WorkflowId $workflowId, Process $process, Task $task)
 {
     $event = self::occur($workflowId->toString(), ['process_id' => $process->id()->toString(), 'task_id' => $task->id()->toString()]);
     $event->workflowId = $workflowId;
     $event->processId = $process->id();
     $event->taskId = $task->id();
     return $event;
 }
Esempio n. 2
0
 /**
  * @test
  */
 function it_returns_a_emulated_process_data_message_when_its_type_is_process_data()
 {
     $messageHandler = $this->getArticleImporterMessageHandler();
     $task = Task::setUp($messageHandler, Task\TaskType::processData(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100]));
     $message = $task->emulateWorkflowMessage();
     $this->assertInstanceOf(Message::class, $message);
     $this->assertTrue($message->messageType()->isProcessDataMessage());
     $this->assertEquals($task->processingType()->of(), $message->processingType()->of());
     $this->assertEquals($task->metadata()->toArray(), $message->processingMetadata()->toArray());
 }
 /**
  * @param Task $task
  * @param Workflow $workflow
  * @return TaskProcessNotFound
  */
 public static function of(Task $task, Workflow $workflow)
 {
     return new self(sprintf("Workflow %s (%s) has no process defined which has task %s on its task list", $workflow->name(), $workflow->workflowId()->toString(), $task->id()->toString()));
 }
Esempio n. 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);
 }
 /**
  * @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());
 }
 /**
  * @test
  */
 function it_returns_a_emulated_data_processed_answer_when_it_is_target_connector()
 {
     $messageHandler = $this->getMessageHandler(MessageHandler\DataDirection::DIRECTION_TARGET, MessageHandler\HandlerType::TYPE_CONNECTOR, ['chunk_support' => true]);
     $connectedTask = Task::setUp($messageHandler, TaskType::processData(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100]));
     $answer = $messageHandler->emulateAnswerMessage($connectedTask);
     $this->assertInstanceOf(Message::class, $answer);
     $this->assertTrue($answer->messageType()->isDataProcessedMessage());
     $this->assertEquals($connectedTask->processingType()->of(), $answer->processingType()->of());
     $this->assertEquals($connectedTask->metadata()->toArray(), $answer->processingMetadata()->toArray());
 }