Pop the next job off of the queue.

@param  string  $queue
@return Job|null
763298
public function pop($queue = null)
	{
		$queue = $this->getQueue($queue);

		$response = $this->sqs->receiveMessage(
			['QueueUrl' => $queue, 'AttributeNames' => ['ApproximateReceiveCount']]
		);

		if (count($response['Messages']) > 0) {
			if ($this->jobCreator) {
				return call_user_func($this->jobCreator, $this->container, $this->sqs, $queue, $response);
			} else {
				return new SqsJob($this->container, $this->sqs, $queue, $response['Messages'][0]);
			}
		}
	}
1041940
public function pop() :? Job
    {
        $key = $this->generateListKey();

        $element = $this->getFirstElementFromQueue($key);
        if ($element === null) {
            return null;
        }

        // Atomic ZPOP
        $this->getClient()->getRedis()->watch($key);
        while (!$this->getClient()->getRedis()->multi()->zrem($key, $element)->exec()) {
            $element = $this->getFirstElementFromQueue($key);
        }

        $this->getClient()->getRedis()->unwatch($key);

        $ref = \explode(':', $element);
        $jobId = \end($ref);
        return new Job($this, $jobId);
    }
606446
private function hasRunningJobInQueue($queue)
    {
        $running = $this->configurationManager->findByQueueAndState($queue, JobState::STATE_RUNNING);

        return null !== $running;
    }
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);
    }
320017
protected function getNextAvailableJob($queue)
    {

        $job = $this->db->name($this->table)
            ->lock(true)
            ->where('queue', $this->getQueue($queue))
            ->where(function (Query $query) {
                $query->where(function (Query $query) {
                    $query->whereNull('reserved_at')
                        ->where('available_at', '<=', $this->currentTime());
                });

                //超时任务重试
                $expiration = Carbon::now()->subSeconds($this->retryAfter)->getTimestamp();

                $query->whereOr(function (Query $query) use ($expiration) {
                    $query->where('reserved_at', '<=', $expiration);
                });
            })
            ->order('id', 'asc')
            ->find();

        return $job ? (object) $job : null;
    }
663966
public function removeJob($id = null) {
		$this->request->allowMethod('post');
		$queuedJob = $this->QueuedJobs->get($id);

		$this->QueuedJobs->delete($queuedJob);

		$this->Flash->success('Job # ' . $id . ' deleted');

		return $this->redirect(['action' => 'index']);
	}
634667
public function pop($queue)
    {
        $item = $this->getClient()->lpop($this->getKey(self::QUEUE_KEY . $queue));

        if (!$item) {
            return null;
        }

        return json_decode($item, true);
    }
1360219
public function pop()
    {
        if (!$this->count()) {
            return null;
        }

        $task = $this->getQueue()->dequeue();

        return $this->unserializeTask($task, '');
    }
81211
protected function getQueue($queue)
    {
        if (is_array($queue)) {
            if (count($queue) > 1) {
                $queues = array_map([$this->queues, 'create'], $queue);

                return new RoundRobinQueue($queues);
            }

            $queue = $queue[0];
        }

        return $this->queues->create($queue);
    }
583541
public function get(string $queue = 'default')
    {
        $message = yield $this->kafka->consume();
        if (!is_object($message)) {
            return false;
        }

        if ($message->err === RD_KAFKA_RESP_ERR_NO_ERROR) {//正常
            return $message->payload;
        } elseif ($message->err === RD_KAFKA_RESP_ERR__PARTITION_EOF) {//暂时没有消息
            return null;
        } elseif ($message->err === RD_KAFKA_RESP_ERR__TIMED_OUT) {//超时
            return false;
        } else {
            throw new \RdKafka\Exception('RD_KAFKA_RESP_ERR', $message->err);//其他异常
        }
    }
1203231
protected function getNextJob($connection, $queue)
    {
        try {
            foreach (explode(',', $queue) as $queue) {
                if (!is_null($job = $connection->pop($queue))) {
                    return $job;
                }
            }
        } catch (Exception $e) {
            $this->report($e);

            $this->stopWorkerIfLostConnection($e);

            $this->sleep(1);
        } catch (Throwable $e) {
            $e = new FatalThrowableError($e);
            $this->report($e);

            $this->stopWorkerIfLostConnection($e);

            $this->sleep(1);
        }
    }
661099
public function pop($stash = null)
    {
        $this->arguments[] = 'pop';
        if ($stash) {
            $this->arguments[] = 'stash@{' . $stash . '}';
        }
        return $this->run();
    }
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;
    }
955401
public function queueOn($queue)
    {
        return $this->mailer->queueOn($queue, $this->view, $this->data, $this->prepareCallback());
    }
1190088
public function pop($queue = null)
    {
        $queue = $queue ?: $this->queue;

        $result = $this->client->reserveMessage($queue);

        if (!$result) {
            return null;
        }

        $message = new QueueMessage();

        $message->setId($result->id);
        $message->setAttempts($result->reserved_count);
        $message->setBody(json_decode($result->body, true));
        $message->setRawBody($result->body);
        $message->setQueueName($queue ?: $this->queue);
        $message->set('reservation_id', $result->reservation_id);

        return $message;
    }
1158684
public function pop($queue = null)
    {
        $queue = $queue ?: $this->queue;

        $this->queueDeclare($queue);

        $this->channel->basic_qos(null, 1, null);
        $result = $this->channel->basic_get($queue, false);

        if (!$result) {
            return null;
        }

        $message = new QueueMessage();

        $message->setId(0);
        $message->setBody(json_decode($result->body, true));
        $message->setRawBody($result->body);
        $message->setQueueName($queue ?: $this->queue);

        // Delivery tag
        $message->set('delivery_tag', $result->delivery_info['delivery_tag']);

        // Attempts
        $attempts = $message->get('attempts', 0) + 1;

        $message->setAttempts($attempts);
        $message->set('attempts', $attempts);

        return $message;
    }
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;
    }