/** * @return ProcessId */ public function processId() { if (is_null($this->processId)) { $this->processId = ProcessId::fromString($this->payload['process_id']); } return $this->processId; }
/** * @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())); }
/** * 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; }
/** * @param ProcessId $other * @return bool */ public function equals(ProcessId $other) { return $this->toString() === $other->toString(); }
/** * @param Process $other * @return bool */ public function sameAs(Process $other) { return $this->processId->equals($other->id()); }