/** * @param Message $startMessage * @param Workflow $workflow * @return StartMessageWasAssignedToWorkflow */ public static function record(Message $startMessage, Workflow $workflow) { $event = self::occur($workflow->workflowId()->toString(), ['start_message' => ['message_type' => $startMessage->messageType()->toString(), 'processing_type' => $startMessage->processingType()->of(), 'metadata' => $startMessage->processingMetadata()->toArray()]]); $event->workflowId = $workflow->workflowId(); $event->startMessage = $startMessage; return $event; }
/** * @param Process $process * @param Workflow $workflow * @return ProcessWasAddedToWorkflow */ public static function record(Process $process, Workflow $workflow) { $event = self::occur($workflow->workflowId()->toString(), ['process_id' => $process->id()->toString(), 'process_type' => $process->type()->toString(), 'task_list' => array_map(function (TaskId $taskId) { $taskId->toString(); }, $process->tasks())]); $event->workflowId = $workflow->workflowId(); $event->processId = $process->id(); $event->processType = $process->type(); $event->tasks = $process->tasks(); return $event; }
/** * @param Workflow $workflow * @throws \RuntimeException * @return void */ public function writeToProcessingConfig(Workflow $workflow) { $processNum = count($workflow->processList()); if ($processNum == 0) { $this->commandBus->dispatch(RemoveProcessConfig::ofProcessTriggeredByMessage($workflow->startMessage()->messageName(), $this->processingConfigLocation)); return; } $processDefinitions = $this->processingConfig->getProcessDefinitions(); if ($processNum == 1) { $processConfig = $this->translateToProcessingProcess($workflow->processList()[0]); $processConfig['name'] = $workflow->name(); if (isset($processDefinitions[$workflow->startMessage()->messageName()])) { $this->commandBus->dispatch(ChangeProcessConfig::ofProcessTriggeredByMessage($workflow->startMessage()->messageName(), $processConfig, $this->processingConfigLocation)); } else { $this->commandBus->dispatch(AddNewProcessToConfig::fromDefinition($processConfig['name'], $processConfig['process_type'], $workflow->startMessage()->messageName(), $processConfig['tasks'], $this->processingConfigLocation)); } } else { throw new \RuntimeException("Handling of more than process per workflow is not supported yet!"); } }
/** * @test * @dataProvider provideStartScenarios */ function it_determines_one_start_task_managed_by_one_process_as_long_as_message_handler_is_located_on_the_same_processing_node(Workflow\Message $startMessage, MessageHandler $firstMessageHandler, ProcessingMetadata $taskMetadata, $expectedTaskType, $expectedProcessType) { $workflow = Workflow::locatedOn(NodeName::defaultName(), WorkflowId::generate(), 'Article Export'); //Pop the WorkflowWasCreatedEvent $this->extractRecordedEvents($workflow); $tasks = $workflow->determineFirstTasks($startMessage, $firstMessageHandler, $taskMetadata); $this->assertEquals(1, count($tasks)); $this->assertInstanceOf(Task::class, $tasks[0]); $this->assertEquals($expectedTaskType, $tasks[0]->type()->toString()); $this->assertTrue($firstMessageHandler->messageHandlerId()->equals($tasks[0]->messageHandlerId())); $domainEvents = $this->extractRecordedEvents($workflow); $this->assertEquals(3, count($domainEvents)); $this->assertInstanceOf(Workflow\StartMessageWasAssignedToWorkflow::class, $domainEvents[0]); $this->assertInstanceOf(Workflow\ProcessWasAddedToWorkflow::class, $domainEvents[1]); $this->assertInstanceOf(Workflow\TaskWasAddedToProcess::class, $domainEvents[2]); foreach ($domainEvents as $domainEvent) { if ($domainEvent instanceof Workflow\ProcessWasAddedToWorkflow) { $this->assertEquals($expectedProcessType, $domainEvent->processType()->toString()); } } }
/** * @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())); }
/** * @param int $desiredReleaseNumber * @param Workflow $workflow * @return WorkflowReleaseAlreadyExists */ public static function withReleaseNumber($desiredReleaseNumber, Workflow $workflow) { return new self(sprintf('A workflow release for workflow %s (%s) with the release number %s already exists', $workflow->name(), $workflow->workflowId()->toString(), $desiredReleaseNumber)); }
/** * @param WorkflowId $workflowId * @param string $workflowName * @return Workflow */ public function setUpNewWorkflow(WorkflowId $workflowId, $workflowName) { return Workflow::locatedOn($this->nodeName(), $workflowId, $workflowName); }
/** * @param Workflow $workflow * @return StartTaskIsAlreadyDefined */ public static function forWorkflow(Workflow $workflow) { return new self(sprintf('Workflow %s already has a start task', $workflow->name())); }