Exemple #1
0
 protected function initFinish(LmStateDto $lmStateDto)
 {
     $this->dtoContainer->setDto($lmStateDto);
     $this->loop->nextTick(function () {
         $this->loop->stop();
     });
     $this->finishingInitialized = true;
     return null;
 }
Exemple #2
0
 protected function generateProcessOrSkipGeneration(LmStateDto $receivedControlDto)
 {
     $processesNumber = count($this->processes);
     if ($processesNumber < $this->tasks && ($this->processManagerDto->getMaxSimultaneousProcesses() > 1 ? $processesNumber < $this->processManagerDto->getMaxSimultaneousProcesses() : true)) {
         $this->logger->info("PM come to create new process.");
         $this->logger->info("Tasks number:" . serialize($this->tasks));
         $this->logger->info("Processes number:" . serialize(count($this->processes)));
         $workerProcess = new Process($this->processManagerDto->getWorkerProcessCommand());
         $workerProcess->start($this->loop);
         $workerProcessPid = $workerProcess->getPid();
         //to protect from bug of proc_get_status
         if (!is_null($workerProcessPid)) {
             if ($this->processManagerDto->getPerformerSocketsParams()) {
                 $workerProcess->stdin->write(json_encode($this->getPreparedSocketParams()));
             }
             $workerProcess->stdout->on(EventsConstants::DATA, function ($data) use(&$workerProcessPid) {
                 //$data = @json_decode($data);
                 //$this->logger->warning("Worker STDOUT: " . serialize($data));
             });
             $workerProcess->on(EventsConstants::PROCESS_EXIT, function ($exitCode, $termSignal) {
                 $this->logger->warning("Worker sub-process exit with code: " . serialize($exitCode) . " | and term signal: " . serialize($termSignal));
             });
             $processDto = $this->getProcessDto($workerProcessPid);
             $this->processes[$workerProcessPid] = $workerProcess;
             $this->dtoContainer->setDto($processDto);
         } else {
             $this->dtoContainer->setDto(new PmStateDto());
         }
     } else {
         //all processes already created, but not finished yet
         if (!$this->allTasksCreated) {
             $this->allTasksCreated = true;
         }
         $pmStateDto = new PmStateDto();
         $pmStateDto->setAllProcessesCreated(true);
         $this->dtoContainer->setDto($pmStateDto);
         $this->logger->info("PM send all processes created.");
         $this->logger->info("Tasks number:" . serialize($this->tasks));
         $this->logger->info("Processes number:" . count($this->processes));
     }
     return null;
 }