@param int $nbJobs

@return mixed
961471
public function findLastJobsWithError($nbJobs = 10)
    {
        return $this->_em->createQuery('SELECT j FROM JMSJobQueueBundle:Job j WHERE j.state IN (:errorStates) AND j.originalJob IS NULL ORDER BY j.closedAt DESC')
            ->setParameter('errorStates', [Job::STATE_TERMINATED, Job::STATE_FAILED])
            ->setMaxResults($nbJobs)
            ->getResult();
    }
40339
public function getJobs($limit = null)
    {
        $qb = $this->em->createQueryBuilder();
        $qb->select('job')
                ->from($this->jobEntityName, 'job')
                ->where(sprintf("job.%s = :job_status_active", $this->jobStatusColumn))
                ->orderBy(sprintf('job.%s', $this->jobPriorityColumn), 'DESC')
                ->addOrderBy(sprintf('job.%s', $this->jobDateLastRunColumn), 'ASC')
                ->setParameter('job_status_active', JobInterface::STATUS_ACTIVE);

        if (null !== $limit) {
            $qb->setMaxResults($limit);
        }

        return $qb->getQuery()->getResult();
    }
1357615
protected function doesntExpectJobs($jobs)
    {
        $jobs = is_array($jobs) ? $jobs : func_get_args();

        $this->withoutJobs();

        $this->beforeApplicationDestroyed(function () use ($jobs) {
            $this->assertEmpty(
                $dispatched = $this->getDispatchedJobs($jobs),
                'These unexpected jobs were dispatched: ['.implode(', ', $dispatched).']'
            );
        });

        return $this;
    }
727600
public function findRootJobByJobNameAndStatuses($jobName, array $statuses)
    {
        return $this->createJobQueryBuilder('job')
            ->where('job.rootJob is NULL and job.name = :jobName and job.status in (:statuses)')
            ->andWhere('job.interrupted != true')
            ->setParameter('jobName', $jobName)
            ->setParameter('statuses', $statuses)
            ->setMaxResults(1)
            ->getQuery()
            ->getOneOrNullResult();
    }
1068508
public static function getAvailableList($includeConcreteDirJobs = 1)
    {
        $jobObjs = array();

        //get existing jobs
        $existingJobHandles = array();
        $existingJobs = static::getList();
        foreach ($existingJobs as $j) {
            $existingJobHandles[] = $j->getJobHandle();
        }

        if (!$includeConcreteDirJobs) {
            $jobClassLocations = array(DIR_FILES_JOBS);
        } else {
            $jobClassLocations = static::jobClassLocations();
        }

        foreach ($jobClassLocations as $jobClassLocation) {
            // Open a known directory, and proceed to read its contents
            if (is_dir($jobClassLocation)) {
                if ($dh = opendir($jobClassLocation)) {
                    while (($file = readdir($dh)) !== false) {
                        if (substr($file, strlen($file) - 4) != '.php') {
                            continue;
                        }

                        $alreadyInstalled = 0;
                        foreach ($existingJobHandles as $existingJobHandle) {
                            if (substr($file, 0, strlen($file) - 4) == $existingJobHandle) {
                                $alreadyInstalled = 1;
                                break;
                            }
                        }
                        if ($alreadyInstalled) {
                            continue;
                        }

                        $jHandle = substr($file, 0, strlen($file) - 4);
                        $className = static::getClassName($jHandle);
                        $jobObjs[$jHandle] = Core::make($className);
                        $jobObjs[$jHandle]->jHandle = $jHandle;
                    }
                    closedir($dh);
                }
            }
        }

        return $jobObjs;
    }
1291531
public function getNbResults()
    {
        if (!isset($this->nbResults)) {
            $this->nbResults = $this->tagsService->getTagChildrenCount($this->tag);
        }

        return $this->nbResults;
    }
883224
public function requestJob()
    {
        $findCond = [
            'conditions' => [
                'completed' => 0
            ],
            'order' => [
                'created ASC',
                'id ASC',
            ],
            'limit' => 3,
        ];

        $jobs = $this->find('all', $findCond)->all()->toArray();
        for ($i=0; $i<count($jobs); $i++) {
            if ($jobs[$i]['stats']['tries'] >= $this->maxTries) {
                unset($jobs[$i]);
            }
        }
        return $jobs;
    }
899370
public function getJobTasks($job)
    {
        $jobId = Utilities::getEntityId(
            $job,
            'WindowsAzure\MediaServices\Models\Job'
        );

        $propertyList = $this->_getEntityList("Jobs('{$jobId}')/Tasks");
        $result = [];

        foreach ($propertyList as $properties) {
            $result[] = Task::createFromOptions($properties);
        }

        return $result;
    }
891188
public function getJobList()
    {
        $propertyList = $this->_getEntityList('Jobs');
        $result = [];

        foreach ($propertyList as $properties) {
            $result[] = Job::createFromOptions($properties);
        }

        return $result;
    }
304387
public function getJob($job_id) {
        if (!$this->job_pool->has($job_id)) {
            $job = $this->job_data->find($job_id);

            // bugfix - class can\'t start with backslash
            $job->runner_class = trim($job->runner_class, '\\');

            $this->job_pool->add($job);
        }

        $job = $this->job_pool->get($job_id);

        return $job;
    }
1003531
public function hasPendingJob()
    {
        // We care about any queued job in the immediate queue, or any queue if the job is already running
        /** @var QueuedJobDescriptor $immediateJob */
        $immediateJob = $this->getQueuedJobService()
            ->getJobList(QueuedJob::IMMEDIATE)
            ->filter([
                'Implementation' => CheckForUpdatesJob::class
            ])
            ->exclude([
                'JobStatus' => [
                    QueuedJob::STATUS_COMPLETE,
                    QueuedJob::STATUS_CANCELLED,
                    QueuedJob::STATUS_BROKEN
                ]
            ]);

        /** @var QueuedJobDescriptor $runningJob */
        $runningJob = QueuedJobDescriptor::get()
            ->filter([
                'Implementation' => CheckForUpdatesJob::class,
                'JobStatus' => QueuedJob::STATUS_RUN,
            ]);

        return $immediateJob->exists() || $runningJob->exists();
    }
1234860
public function getNbResults()
    {
        if (isset($this->nbResults)) {
            return $this->nbResults;
        }

        return $this->nbResults = $this->getSearchResultWithLimitZero()->totalCount;
    }
844889
public static function getSitesForUser($nb_user)
    {
        if (is_numeric ($nb_user_id = nb_getMixedValue($nb_user, NABU_USER_FIELD_ID))) {
            $retval = CNabuSiteUser::buildObjectListFromSQL(
                'nb_site_id',
                'SELECT su.*
                   FROM nb_site_user su, nb_user u, nb_site s
                  WHERE su.nb_user_id=u.nb_user_id
                    AND su.nb_site_id=s.nb_site_id
                    AND su.nb_user_id=%user_id$d',
                array(
                    'user_id' => $nb_user_id
                ),
                ($nb_user instanceof CNabuUser ? $nb_user : null)
            );
        } else {
            $retval = new CNabuSiteUserList();
        }

        return $retval;
    }
530471
protected function expectsJobs($jobs)
    {
        $jobs = is_array($jobs) ? $jobs : func_get_args();

        $this->withoutJobs();

        $this->beforeApplicationDestroyed(function () use ($jobs) {
            $dispatched = $this->getDispatchedJobs($jobs);

            $this->assertEmpty(
                $jobsNotDispatched = array_diff($jobs, $dispatched),
                'These expected jobs were not dispatched: ['.implode(', ', $jobsNotDispatched).']'
            );
        });

        return $this;
    }
833930
public function getNbResults()
    {
        if (isset($this->nbResults)) {
            return $this->nbResults;
        }

        $countQuery = clone $this->query;
        $countQuery->limit = 0;

        return $this->nbResults = $this->searchService->findLocations($countQuery)->totalCount;
    }
1044091
public function getJob($queues, $timeoutMs = 200) {
        $jobs = $this->getJobs($queues, 1, $timeoutMs);

        if (empty($jobs)) {
            return null;
        }

        return $jobs[0];
    }
1262080
public function setJobs(\ArrayObject $jobs)
    {
        $this->jobs = new \ArrayObject();
        foreach ($jobs as $job) {
            $this->addJob($job);
        }
        
        return $this;
    }