Пример #1
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;
 }
Пример #2
0
 /**
  * @test
  */
 function it_is_created_with_a_specific_process_type_and_an_empty_task_list()
 {
     $process = Process::ofType(ProcessType::linearMessaging(), ProcessId::generate());
     $this->assertTrue(ProcessType::linearMessaging()->equals($process->type()));
     $this->assertEmpty($process->tasks());
 }