Called automatically. Checks whether if the queue is full. If not, tries to pull more jobs from backlog and 'more'
@return void
487098
public function checkQueue()
    {
        if ($this->backlog !== null) {
            while (!$this->backlog->isEmpty()) {
                if ($this->maxConcurrency !== -1 && ($this->jobsNum - $this->resultsNum > $this->maxConcurrency)) {
                    return;
                }
                list($name, $cb) = $this->backlog->shift();
                $this->addJob($name, $cb);
            }
        }
        if ($this->more !== null) {
            $this->more();
        }
    }
294963
protected function doExecute()
    {
        $failer = $this->console->container->get('queue.failer');

        $all = $this->getOption('all');

        if ($all) {
            $ids = array_column($failer->all(), 'id');
        } else {
            $ids = $this->io->getArguments();

            if (!count($ids)) {
                throw new WrongArgumentException('No id provided');
            }
        }

        foreach ($ids as $id) {
            $failer->remove($id);

            if (!$all) {
                $this->out(sprintf('Remove failed-job: <info>%s</info>', $id));

                $failer->remove($id);
            }
        }

        if ($all) {
            $failer->clear();

            $this->out('All failed jobs cleared.');
        }

        return true;
    }
284890
public function processQueue()
    {
        //Set items to 0
        $this->totalItems = 0;

        //Set bulk sync limit
        $this->bulkSyncLimit = 5;

        //Set priority
        $this->_setPriority();

        //Check previous import status
        $this->_checkImportStatus();

        //Bulk priority. Process group 1 first
        foreach ($this->bulkPriority as $bulk) {
            if ($this->totalItems < $bulk['limit']) {
                $collection = $this->_getQueue(
                    $bulk['type'],
                    $bulk['mode'],
                    $bulk['limit'] - $this->totalItems
                );
                if ($collection->getSize()) {
                    $this->totalItems += $collection->getSize();
                    $bulkModel = $this->objectManager->create($bulk['model']);
                    $bulkModel->sync($collection);
                }
            }
        }

        //reset total items to 0
        $this->totalItems = 0;

        //Single/Update priority.
        foreach ($this->singlePriority as $single) {
            if ($this->totalItems < $single['limit']) {
                $collection = $this->_getQueue(
                    $single['type'],
                    $single['mode'],
                    $single['limit'] - $this->totalItems
                );
                if ($collection->getSize()) {
                    $this->totalItems += $collection->getSize();
                    $singleModel = $this->objectManager->create(
                        $single['model']
                    );
                    $singleModel->sync($collection);
                }
            }
        }
    }
996013
private function addNextRequests()
    {
        $limit = max($this->getPoolSize() - count($this->waitQueue), 0);
        while ($limit--) {
            if (!$this->addNextRequest()) {
                break;
            }
        }
    }
1219505
protected function shouldBeDelayed(): bool
    {
        if ($this->job && \is_null($this->model)) {
            $this->release(10);

            return true;
        }

        return false;
    }
354683
public function process_stage_queueorwait() {
        global $DB;

        $wait = $this->instance->get_export_config('wait');
        if (empty($wait)) {
            $DB->set_field('portfolio_tempdata', 'queued', 1, array('id' => $this->id));
            $this->queued = true;
            return $this->process_stage_finished(true);
        }
        return true;
    }
479289
public function doneWorking()
    {
        Event::fire(Event::WORKER_DONE_WORKING, array($this, $this->job));

        $this->redis->hmset(self::redisKey($this), array(
            'job_id'      => '',
            'job_pid'     => 0,
            'job_started' => 0
        ));

        switch ($this->job->getStatus()) {
            case Job::STATUS_COMPLETE:
                $this->redis->hincrby(self::redisKey($this), 'processed', 1);
                break;
            case Job::STATUS_CANCELLED:
                $this->redis->hincrby(self::redisKey($this), 'cancelled', 1);
                break;
            case Job::STATUS_FAILED:
                $this->redis->hincrby(self::redisKey($this), 'failed', 1);
                break;
        }

        $this->job = null;
    }
1120369
protected function refreshQueues()
    {
        if ($this->refreshQueues) {
            $this->queues = $this->resque->queues();
        }

        if (!$this->queues) {
            if ($this->refreshQueues) {
                $this->logger->info('Refreshing queues dynamically, but there are no queues yet');
            } else {
                $this->logger->notice('Not listening to any queues, and dynamic queue refreshing is disabled');
                $this->shutdownNow();
            }
        }

        // Each call to reserve, we check the queues in a different order
        if ($this->options['shuffle_queues']) {
            shuffle($this->queues);
        } elseif ($this->options['sort_queues']) {
            sort($this->queues);
        }
    }
57791
public function checkFree()
    {
        $this->setFree(!$this->finished && !$this->acquired && (!$this->onResponse || $this->onResponse->count() < $this->maxQueue));
    }
12523
public function Fill()
	{
		if ( $this->src->getIsFinished() ) return;

		foreach ( $this->src as $fact )
		{
			$this->buffer[] = $fact;
		}
		// while ( $this->src->MoveNext() )
		// {
		// 	$this->buffer[] = $this->src->getCurrent();
		// }

		$this->filled = true;
		$this->empty = ! count( $this->buffer );
	}
726839
public function isFull()
    {
        return (bool) (pow($this->size, 2) == count(array_filter(array_reduce($this->getBoard(), 'array_merge', []))));
    }
449632
protected function autoEnqueue()
    {
        $request = MocaBonita::getInstance()->getMbRequest();

        if ($request->isLoginPage()) {
            $this->actionEnqueue = "login_enqueue_scripts";
        } elseif ($request->isAdmin()) {
            $this->actionEnqueue = "admin_enqueue_scripts";
        } else {
            $this->actionEnqueue = "wp_enqueue_scripts";
        }
    }
544196
public function clean() {
		if (!Configure::read('Queue.cleanuptimeout')) {
			$this->abort('You disabled cleanuptimout in config. Aborting.');
		}

		$this->out('Deleting old jobs, that have finished before ' . date('Y-m-d H:i:s', time() - (int)Configure::read('Queue.cleanuptimeout')));
		$this->QueuedJobs->cleanOldJobs();
		$this->QueueProcesses->cleanEndedProcesses();
	}
658167
protected function checkLuck()
    {
        $i = 1;
        while (true) {
            $fib = $this->fib($i);
            if ($fib == $this->counter) return true;
            if ($fib > $this->counter) return false;
            $i++;
        }
    }
741766
public function isPendingCountOk($queue)
    {
        if ($queue->alert_pending_jobs_greater_than < 1) {
            return true;
        }

        if ($this->getPendingJobsCount($queue) <= $queue->alert_pending_jobs_greater_than) {
            if ($this->eye->status()->isSick('queue_pending_jobs_'.$queue->id)) {
                $this->eye->notifier()->alert(new PendingCountOk(['queue' => $queue, 'pending_job_count' => $this->getPendingJobsCount($queue)]));
            }

            $this->eye->status()->setHealthy('queue_pending_jobs_'.$queue->id);

            return true;
        }

        if ($this->eye->status()->isHealthy('queue_pending_jobs_'.$queue->id)) {
            $this->eye->notifier()->alert(new PendingCountExceeded(['queue' => $queue, 'pending_job_count' => $this->getPendingJobsCount($queue)]));
        }

        $this->eye->status()->setSick('queue_pending_jobs_'.$queue->id);

        return false;
    }
392752
protected function executeNextJob(): void
    {
        while ($this->jobs) {
            $job = \array_pop($this->jobs);
            
            if ($job->state & AbstractPromise::PENDING) {
                $done = false;
                
                (new Coroutine($job->context, $job->generator))->when(function (?\Throwable $e, $v = null) use ($job, & $done) {
                    if ($e) {
                        $job->fail($e);
                    } else {
                        $job->resolve($v);
                    }
                    
                    if ($done) {
                        $this->executeNextJob();
                    } else {
                        $done = true;
                    }
                });
                
                if (!$done) {
                    $done = true;
                    
                    return;
                }
            }
        }
        
        $this->running--;
    }
379350
protected function is_queue_empty() {
		global $wpdb;

		$table  = $wpdb->options;
		$column = 'option_name';

		if ( is_multisite() ) {
			$table  = $wpdb->sitemeta;
			$column = 'meta_key';
		}

		$key = $this->identifier . '_batch_%';

		$count = $wpdb->get_var( $wpdb->prepare( "
			SELECT COUNT(*)
			FROM {$table}
			WHERE {$column} LIKE %s
		", $key ) );

		return ( $count > 0 ) ? false : true;
	}