@classmethod
  def ClaimNotificationsForCollection(cls,
                                      token=None,
                                      start_time=None,
                                      lease_time=200,
                                      collection=None):
    """Return unclaimed hunt result notifications for collection.

    Args:
      token: The security token to perform database operations with.

      start_time: If set, an RDFDateTime indicating at what point to start
        claiming notifications. Only notifications with a timestamp after this
        point will be claimed.

      lease_time: How long to claim the notifications for.

      collection: The urn of the collection to find notifications for. If unset,
        the earliest (unclaimed) notification will determine the collection.

    Returns:
      A pair (collection, results) where collection is the collection that
      notifications were retrieved for and results is a list of tuples (id,
      timestamp, suffix) where id identifies the notification within the queue
      and (stimestmp, suffix) identifies the GrrMessage within the result
      collection.

    """

    class CollectionFilter(object):

      def __init__(self, collection):
        self.collection = collection

      def FilterRecord(self, notification):
        if self.collection is None:
          self.collection = notification.result_collection_urn
        return self.collection != notification.result_collection_urn

    f = CollectionFilter(collection)
    results = []
    with aff4.FACTORY.OpenWithLock(RESULT_NOTIFICATION_QUEUE,
                                   aff4_type="HuntResultQueue",
                                   lease_time=300,
                                   blocking=True,
                                   blocking_sleep_interval=15,
                                   blocking_lock_timeout=600,
                                   token=token) as queue:
      for record_id, value in queue.ClaimRecords(record_filter=f.FilterRecord,
                                                 start_time=start_time,
                                                 timeout=lease_time,
                                                 limit=100000):
        results.append((record_id, value.timestamp, value.suffix))
    return (f.collection, results)
dataset/ETHPy150Open google/grr/grr/lib/hunts/results.py/HuntResultQueue.ClaimNotificationsForCollection/original