Pop the next job off of the queue.

@param  string  $queue
@return \Illuminate\Contracts\Queue\Job|null
320161
public function pop($queue = null)
    {
        $this->migrate($prefixed = $this->getQueue($queue));

        if (empty($nextJob = $this->retrieveNextJob($prefixed))) {
            return;
        }

        [$job, $reserved] = $nextJob;

        if ($reserved) {
            return new RedisJob(
                $this->container, $this, $job,
                $reserved, $this->connectionName, $queue ?: $this->default
            );
        }
    }
1147554
public function pop(array $queues, $timeout = 10, $blocking = true)
    {
        $queue = $payload = null;

        foreach ($queues as $key => $queue) {
            $queues[$key] = self::redisKey($queue);
        }

        if ($blocking) {
            list($queue, $payload) = $this->redis->blpop($queues, $timeout);
            $queue = $this->redis->removeNamespace($queue);
        } else {
            foreach ($queues as $queue) {
                if ($payload = $this->redis->lpop($queue)) {
                    break;
                }
            }
        }

        if (!$queue or !$payload) {
            return false;
        }

        $queue = substr($queue, strlen('queue:'));

        return Job::loadPayload($queue, $payload);
    }
1136962
protected function retrieveNextJob($queue, $block = true)
    {
        $nextJob = $this->getConnection()->eval(
            LuaScripts::pop(), 3, $queue, $queue.':reserved', $queue.':notify',
            $this->availableAt($this->retryAfter)
        );

        if (empty($nextJob)) {
            return [null, null];
        }

        [$job, $reserved] = $nextJob;

        if (! $job && ! is_null($this->blockFor) && $block &&
            $this->getConnection()->blpop([$queue.':notify'], $this->blockFor)) {
            return $this->retrieveNextJob($queue, false);
        }

        return [$job, $reserved];
    }
389995
public function queue($queue = null)
    {
        return $this->mailer->queue($this->view, $this->data, $this->prepareCallback(), $queue);
    }
533596
protected function releaseJobsThatHaveBeenReservedTooLong($queue)
	{
		$expired = Carbon::now()->subSeconds($this->expire)->getTimestamp();

		$this->database->table($this->table)
					->where('queue', $this->getQueue($queue))
					->where('reserved', 1)
					->where('reserved_at', '<=', $expired)
					->update([
						'reserved' => 0,
						'reserved_at' => null,
						'attempts' => new Expression('attempts + 1'),
					]);
	}
453693
public function job($job, $queue = null)
    {
        return $this->call(
            function () use ($job, $queue) {
                $job = is_string($job) ? resolve($job) : $job;

                if ($job instanceof ShouldQueue) {
                    dispatch($job)->onQueue($queue);
                } else {
                    dispatch_now($job);
                }
            }
        )->name(is_string($job) ? $job : get_class($job));
    }
1175101
public function reserve()
    {
        $this->refreshQueues();

        $this->logger->debug('Attempting to reserve job from {queues}', array(
            'queues' => empty($this->queues) ? 'empty queue list' : implode(', ', $this->queues)
        ));

        foreach ($this->queues as $queue) {
            $payload = $this->resque->pop($queue);

            if (!is_array($payload)) {
                continue;
            }

            $payload['queue'] = $queue;

            try {
                $job = $this->createJobInstance($queue, $payload);
            } catch (ResqueException $exception) {
                $this->failJob($payload, $exception);
                return null;
            }

            if ($job) {
                $this->logger->info('Found job on {queue}', array('queue' => $queue));
                return $job;
            }
        }

        return null;
    }
67974
protected function next()
    {
        $promiseOrValue = array_shift($this->queue);
        $promise = resolve($promiseOrValue);
        $this->cancellationQueue->enqueue($promise);
        return $promise;
    }
344000
public function runNextJob($connection, $queue = null, $delay = 0, $sleep = 3, $maxTries = 0)
    {
        $job = $this->getNextJob(
            $this->manager->connection($connection), $queue
        );

        // If we're able to pull a job off of the stack, we will process it and
        // then immediately return back out. If there is no job on the queue
        // we will "sleep" the worker for the specified number of seconds.

        if (! is_null($job)) {
            return $this->runJob($job, $connection, $maxTries, $delay);
        }

        $this->sleep($sleep);

        return array('job' => null, 'failed' => false);
    }
1281417
protected function getNextAvailableJob($queue)
    {
        $expiration = Carbon::now()->subSeconds($this->retryAfter)->getTimestamp();
        $sql = 'SELECT * FROM ' . $this->table . ' WHERE queue =\'' . $this->getQueue($queue) . '\' 
                AND (
                        (reserved_at is NULL AND available_at <=' . $this->currentTime() . ')
                        OR 
                        (reserved_at <= ' . $expiration . ')
                    ) 
                order by id asc limit 1 ';

        $job = $this->database->createCommand($sql)->queryOne();

        return $job ? new DatabaseJobRecord((object)$job) : null;
    }
48706
public function getMessagesTotalCountOnQueue($queue)
    {
        try {
            return $this->queue->statsTube($queue)['total-jobs'];
        } catch (ConnectionException $ex) {
            \PHPUnit\Framework\Assert::fail("queue [$queue] not found");
        }
    }
970505
public function reserve(array $queues, AdapterInterface $adapter): ?Job
    {
        if (in_array('*', $queues, true)) {
            $queues = $adapter->getAllQueueNames();
        }

        foreach ($queues as $queue) {
            $this->log->debug(sprintf('Checking %s', $queue));

            $job = $adapter->reserve($queue);

            if (!is_null($job)) {
                $this->log->debug(sprintf('Found job on %s', $queue));

                return $job;
            }
        }

        return null;
    }
389549
public function buildPipeline(array $queue)
    {
        // First we'll build the queue
        $pipeline = new Pipeline();

        // Get the connections to execute the tasks on
        /** @var ConnectionInterface[] $connections */
        $connections = $this->connections->getActiveConnections();
        foreach ($connections as $connection) {
            $connectionKey = $connection->getConnectionKey();
            $stages = $this->getStages($connectionKey);

            // Add job to pipeline
            foreach ($stages as $stage) {
                $connectionKey->stage = $stage;

                $pipeline[] = new Job([
                    'connectionKey' => clone $connectionKey,
                    'queue' => $queue,
                ]);
            }
        }

        return $pipeline;
    }
632405
public function pop()
    {
        $keys = array_keys($this->queues);

        for ($this->queueCounter; isset($keys[$this->queueCounter]); $this->queueCounter++) {
            $queue = $this->queues[$keys[$this->queueCounter]];

            $message = $queue->pop();

            if ($message !== null) {
                $this->queueCounter++;
                $this->processedMessages++;
                return $message;
            }

            // After the last queue has been popped
            if ((count($this->queues) -1) === $this->queueCounter) {
                $this->queueCounter = 0;

                if ($this->processedMessages === 0) {
                    return null;
                }

                $this->processedMessages = 0;
            }
        }

        return null;
    }
269186
protected function getNextJob($connector, $queue)
    {
        try {
            foreach (explode(',', $queue) as $queue) {
                if (!is_null($job = $connector->pop($queue))) {
                    return $job;
                }
            }
        } catch (Exception | Throwable $e) {
            $this->handle->report($e);
            $this->sleep(1);
        }
    }
427833
protected function getNextAvailableJob($queue)
    {
        $job = $this->database->table($this->table)
            ->lockForUpdate()
            ->where('queue', $this->getQueue($queue))
            ->where(function ($query)
            {
                $this->isAvailable($query);

                $this->isReservedButExpired($query);
            })
            ->orderBy('id', 'asc')
            ->first();

        if (! is_null($job)) {
            return (object) $job;
        }
    }
328016
public function reserve(string $queue): ?Job
    {
        $item = $this->client->lpop(sprintf('queue:%s', $queue));

        if (!$item) {
            return null;
        }

        $payload = json_decode($item, true);

        $id = $payload['id'] ?? null;

        return new Job($payload['class'], $queue, $payload['args'], $id);
    }