public static function prepareErrorExecutionDto($taskId, $errorMsg) { $executionDto = new ExecutionDto(); $executionDto->setErrorExist(true); $executionDto->setTaskId($taskId); $executionDto->setErrorMessage($errorMsg); return $executionDto; }
public function processReceivedControlDto(LmControlDto $receivedControlDto) { $this->currentCpuUsage = $receivedControlDto->getCpuUsage(); $this->currentResidentMemoryUsage = $receivedControlDto->getResidentMemoryUsage(); switch (true) { case $receivedControlDto instanceof LmStateDto: $this->logger->emergency("PM got lmStateDto. Allow generate: " . serialize($receivedControlDto->isAllowGenerate())); /** * @var LmStateDto $receivedControlDto */ if ($receivedControlDto->isAllowGenerate()) { $this->generateProcessOrSkipGeneration($receivedControlDto); } elseif ($receivedControlDto->isAllPidsFinished()) { $this->initFinishing(); } elseif ($receivedControlDto->isCriticalFinish()) { $this->executionDto->setErrorExist(true); $this->executionDto->setCriticalError(true); $this->executionDto->setErrorMessage($receivedControlDto->getCriticalFinishReason()); $this->initFinishing(); $this->logger->warning("PM go to stop due to critical finishing, with reason: " . $receivedControlDto->getCriticalFinishReason()); } else { $this->dtoContainer->setDto(new PmStateDto()); } break; case $receivedControlDto instanceof TerminateDto: /** * @var TerminateDto $receivedControlDto */ $pidsToTerminateOrSigTerm = $receivedControlDto->getPidsForTerminate(); $this->logger->warning("PM receive PIDs to terminate: " . serialize($receivedControlDto)); if (!empty($pidsToTerminateOrSigTerm)) { $processesToTerminate = []; /** * @var Process $process */ foreach ($this->processes as $parentPid => $process) { foreach ($pidsToTerminateOrSigTerm as $key => $pid) { if ($pid === $parentPid) { $processesToTerminate[$pid] = $process; unset($pidsToTerminateOrSigTerm[$key]); unset($this->processes[$pid]); } } } unset($process); /** * @var Process $process */ foreach ($processesToTerminate as $process) { $this->tryTerminateProcess($process); } if ($this->sigTermBlockingAgent) { $this->logger->critical("Pids to terminate: " . serialize($pidsToTerminateOrSigTerm)); $jsonPids = json_encode($this->prepareTerminatePids($pidsToTerminateOrSigTerm)); $this->logger->critical("PM send json: " . $jsonPids); $this->workersPublisherSocket->send($jsonPids); } else { foreach ($pidsToTerminateOrSigTerm as $pid) { $this->trySendSigTerm($pid); } } } $this->dtoContainer->setDto(new PmStateDto()); break; case $receivedControlDto instanceof PauseDto: $this->logger->emergency("PM receive PauseDto: " . serialize($receivedControlDto)); $this->workersPublisherSocket->send(json_encode($this->preparePausePids($receivedControlDto))); $this->dtoContainer->setDto(new PmStateDto()); break; case $receivedControlDto instanceof ContinueDto: $this->logger->emergency("PM receive ContinueDto: " . serialize($receivedControlDto)); $this->workersPublisherSocket->send(json_encode($this->prepareContinuePids($receivedControlDto))); $this->dtoContainer->setDto(new PmStateDto()); break; default: throw new ProcessManagerInvalidArgument("Unknown control dto: " . serialize($receivedControlDto)); } return null; }