Returns a list of Tasks leased for a certain time.

    Args:
      queue: The queue to query from.
      lease_seconds: The tasks will be leased for this long.
      limit: Number of values to fetch.
      timestamp: Range of times for consideration.

    Returns:
        A list of GrrMessage() objects leased.

def QueueQueryAndOwn(self, queue, lease_seconds, limit, timestamp):
    """Returns a list of Tasks leased for a certain time.

    Args:
      queue: The queue to query from.
      lease_seconds: The tasks will be leased for this long.
      limit: Number of values to fetch.
      timestamp: Range of times for consideration.

    Returns:
        A list of GrrMessage() objects leased.
    """
    # Do the real work in a transaction
    try:
      lock = DB.LockRetryWrapper(queue, lease_time=lease_seconds)
      return self._QueueQueryAndOwn(
          lock.subject,
          lease_seconds=lease_seconds,
          limit=limit,
          timestamp=timestamp)
    except DBSubjectLockError:
      # This exception just means that we could not obtain the lock on the queue
      # so we just return an empty list, let the worker sleep and come back to
      # fetch more tasks.
      return []
    except Error as e:
      logging.warning("Datastore exception: %s", e)
      return []