Exemple #1
0
 private function isParallelLimitExceeded()
 {
     // skip validation for components without limit
     if (in_array($this->job->getComponent(), Limits::unlimitedComponents())) {
         $this->logger->debug('isParallelLimitExceeded - NO - unlimited component');
         return false;
     }
     $maxLimit = Limits::getParallelLimit($this->storageApiService->getTokenData());
     /** @var Search $elasticSearch */
     $elasticSearch = $this->getContainer()->get('syrup.elasticsearch.search');
     $jobs = $elasticSearch->getJobs(array('projectId' => $this->job->getProject()['id'], 'query' => sprintf('(%s) AND (%s)', sprintf('status:%s OR status:%s', Job::STATUS_PROCESSING, Job::STATUS_TERMINATING), implode(' AND ', array_map(function ($name) {
         return '-component:' . $name;
     }, Limits::unlimitedComponents())))));
     if (count($jobs) < $maxLimit) {
         $this->logger->debug('isParallelLimitExceeded - NO - free workers ' . ($maxLimit - count($jobs)));
         return false;
     }
     $this->logger->debug('isParallelLimitExceeded - full workers ' . ($maxLimit - count($jobs)));
     if ($this->job->getNestingLevel() >= 1) {
         $runIds = explode('.', $this->job->getRunId());
         unset($runIds[count($runIds) - 1]);
         $jobs = $elasticSearch->getJobs(array('projectId' => $this->job->getProject()['id'], 'query' => sprintf('(%s) AND (%s) AND (%s) AND (%s)', sprintf('status:%s OR status:%s', Job::STATUS_PROCESSING, Job::STATUS_TERMINATING), implode(' AND ', array_map(function ($name) {
             return '-component:' . $name;
         }, Limits::unlimitedComponents())), sprintf('runId:%s.*', implode('.', $runIds)), sprintf('nestingLevel:%s', $this->job->getNestingLevel()))));
         if (!count($jobs)) {
             $this->logger->debug('isParallelLimitExceeded - NO - free at nesting level');
             return false;
         }
     }
     $this->logger->debug('isParallelLimitExceeded - YES - any free worker');
     return true;
 }