Пример #1
0
 /**
  * @test
  */
 function it_can_be_reconstituted_with_a_task_list()
 {
     $task1 = TaskId::generate();
     $task2 = TaskId::generate();
     $process = Process::withTaskList([$task1, $task2], ProcessId::generate(), ProcessType::linearMessaging());
     $this->assertTrue($task1->equals($process->tasks()[0]));
     $this->assertTrue($task2->equals($process->tasks()[1]));
     $this->assertTrue(ProcessType::linearMessaging()->equals($process->type()));
 }
Пример #2
0
 /**
  * Determine the required task(s) to handle the initial workflow message.
  *
  * In most cases only one task is required, but if the message handler is located on another processing node,
  * the workflow needs to set up two tasks. One for triggering a sub process on the remote processing node and
  * one that is assigned to the sub process and actually triggers the processing of the message on the remote node.
  *
  * @param Message $startMessage
  * @param MessageHandler $firstMessageHandler
  * @return Task[]
  * @throws \RuntimeException
  * @throws Workflow\Exception\StartTaskIsAlreadyDefined
  */
 public function determineFirstTasks(Message $startMessage, MessageHandler $firstMessageHandler)
 {
     if ($this->hasStartMessage()) {
         throw StartTaskIsAlreadyDefined::forWorkflow($this);
     }
     $tasks = [];
     $taskMetadata = $startMessage->processingMetadata();
     //@TODO: Implement sub process set up
     if (!$this->processingNodeName()->equals($firstMessageHandler->processingNodeName())) {
         throw new \RuntimeException("Running message handler on different nodes is not supported yet!");
     }
     $task = $this->scheduleTaskFor($firstMessageHandler, $taskMetadata, $startMessage);
     $nextMessage = $task->emulateWorkflowMessage();
     $processType = $this->determineProcessType($nextMessage, $firstMessageHandler);
     $this->recordThat(StartMessageWasAssignedToWorkflow::record($startMessage, $this));
     $process = Process::ofType($processType, ProcessId::generate());
     $this->recordThat(ProcessWasAddedToWorkflow::record($process, $this));
     $this->recordThat(TaskWasAddedToProcess::record($this->workflowId(), $process, $task));
     $tasks[] = $task;
     return $tasks;
 }