/**
  * {@inheritDoc}
  */
 public function pop(array $options = array())
 {
     // First run garbage collection
     $this->purge();
     $conn = $this->connection;
     $conn->beginTransaction();
     try {
         $platform = $conn->getDatabasePlatform();
         $select = 'SELECT * ' . 'FROM ' . $platform->appendLockHint($this->options->getTableName(), LockMode::PESSIMISTIC_WRITE) . ' ' . 'WHERE status = ? AND queue = ? AND scheduled <= ? ' . 'ORDER BY scheduled ASC ' . 'LIMIT 1 ' . $platform->getWriteLockSQL();
         $stmt = $conn->executeQuery($select, array(static::STATUS_PENDING, $this->getName(), new DateTime()), array(Type::SMALLINT, Type::STRING, Type::DATETIME));
         if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
             $update = 'UPDATE ' . $this->options->getTableName() . ' ' . 'SET status = ?, executed = ? ' . 'WHERE id = ? AND status = ?';
             $rows = $conn->executeUpdate($update, array(static::STATUS_RUNNING, new DateTime(), $row['id'], static::STATUS_PENDING), array(Type::SMALLINT, Type::DATETIME, Type::INTEGER, Type::SMALLINT));
             if ($rows != 1) {
                 throw new Exception\LogicException("Race-condition detected while updating item in queue.");
             }
         }
         $conn->commit();
     } catch (DBALException $e) {
         $conn->rollback();
         $conn->close();
         throw new Exception\RuntimeException($e->getMessage(), $e->getCode(), $e);
     }
     if ($row === false) {
         sleep($this->options->getSleepWhenIdle());
         return null;
     }
     $data = json_decode($row['data'], true);
     // Add job ID to meta data
     $data['metadata']['id'] = $row['id'];
     return $this->createJob($data['class'], $data['content'], $data['metadata']);
 }