public function dequeue()
    {
        $queryBuilder = $this->connection->createQueryBuilder();
        $queryBuilder->from($this->table, 'backlog');
        $queryBuilder->andWhere('backlog.status = :status');
        $queryBuilder->setParameter(':status', BacklogService::STATUS_OPEN);
        $queryBuilder->addOrderBy('priority', 'DESC');
        $queryBuilder->addOrderBy('id', 'ASC');
        $queryBuilder->setMaxResults(1);
        $queryBuilder->select('*');

        $backlog = $queryBuilder->execute()->fetch(PDO::FETCH_ASSOC);

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

        $affectedRows = $this->connection->update(
            $this->table,
            [
                'status' => BacklogService::STATUS_PROCESSED,
            ],
            [
                'id' => $backlog['id'],
            ]
        );

        if ($affectedRows !== 1) {
            return null;
        }

        $affectedRows = $this->connection->delete($this->table, [
            'id' => $backlog['id'],
        ]);

        if ($affectedRows !== 1) {
            return null;
        }

        $command = unserialize($backlog['payload'], [
            'allowed_classes' => true, ]
        );

        if (!($command instanceof CommandInterface)) {
            return null;
        }

        return new HandleBacklogElementCommand($command);
    }
public function dequeue()
    {
        $queryBuilder = $this->connection->createQueryBuilder();
        $queryBuilder->from($this->table, 'backlog');
        $queryBuilder->andWhere('backlog.status = :status');
        $queryBuilder->setParameter(':status', BacklogService::STATUS_OPEN);
        $queryBuilder->addOrderBy('priority', 'DESC');
        $queryBuilder->addOrderBy('id', 'ASC');
        $queryBuilder->setMaxResults(1);
        $queryBuilder->select('*');

        $backlog = $queryBuilder->execute()->fetch(PDO::FETCH_ASSOC);

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

        $affectedRows = $this->connection->update(
            $this->table,
            [
                'status' => BacklogService::STATUS_PROCESSED,
            ],
            [
                'id' => $backlog['id'],
            ]
        );

        if ($affectedRows !== 1) {
            return null;
        }

        $affectedRows = $this->connection->delete($this->table, [
            'id' => $backlog['id'],
        ]);

        if ($affectedRows !== 1) {
            return null;
        }

        $command = unserialize($backlog['payload'], [
            'allowed_classes' => true, ]
        );

        if (!($command instanceof CommandInterface)) {
            return null;
        }

        return new HandleBacklogElementCommand($command);
    }
{@inheritdoc}