Пример #1
0
    def post(self, namespace, timestamp):
        digests = []
        now = utils.timestamp_to_datetime(long(timestamp))
        expiration = config.settings().default_expiration
        try:
            digests = payload_to_hashes(self)
            # Requests all the entities at once.
            futures = ndb.get_multi_async(
                model.get_entry_key(namespace, binascii.hexlify(d))
                for d in digests)

            to_save = []
            while futures:
                # Return opportunistically the first entity that can be retrieved.
                future = ndb.Future.wait_any(futures)
                futures.remove(future)
                item = future.get_result()
                if item and item.next_tag_ts < now:
                    # Update the timestamp. Add a bit of pseudo randomness.
                    item.expiration_ts, item.next_tag_ts = model.expiration_jitter(
                        now, expiration)
                    to_save.append(item)
            if to_save:
                ndb.put_multi(to_save)
            logging.info('Timestamped %d entries out of %s', len(to_save),
                         len(digests))
        except Exception as e:
            logging.error('Failed to stamp entries: %s\n%d entries', e,
                          len(digests))
            raise
Пример #2
0
  def post(self, namespace, timestamp):
    digests = []
    now = utils.timestamp_to_datetime(long(timestamp))
    expiration = config.settings().default_expiration
    try:
      digests = payload_to_hashes(self, namespace)
      # Requests all the entities at once.
      futures = ndb.get_multi_async(
          model.entry_key(namespace, binascii.hexlify(d)) for d in digests)

      to_save = []
      while futures:
        # Return opportunistically the first entity that can be retrieved.
        future = ndb.Future.wait_any(futures)
        futures.remove(future)
        item = future.get_result()
        if item and item.next_tag_ts < now:
          # Update the timestamp. Add a bit of pseudo randomness.
          item.expiration_ts, item.next_tag_ts = model.expiration_jitter(
              now, expiration)
          to_save.append(item)
      if to_save:
        ndb.put_multi(to_save)
      logging.info(
          'Timestamped %d entries out of %s', len(to_save), len(digests))
    except Exception as e:
      logging.error('Failed to stamp entries: %s\n%d entries', e, len(digests))
      raise
Пример #3
0
    def post(self, namespace, timestamp):
        saved = 0
        digests = []
        now = utils.timestamp_to_datetime(long(timestamp))
        expiration = config.settings().default_expiration
        try:
            digests = _payload_to_hashes(self, namespace)
            # Requests all the entities at once.
            fetch_futures = ndb.get_multi_async(
                model.get_entry_key(namespace, binascii.hexlify(d))
                for d in digests)

            save_futures = []
            while fetch_futures:
                # Return opportunistically the first entity that can be retrieved.
                fetch_futures, done = _throttle_futures(
                    fetch_futures,
                    len(fetch_futures) - 1)
                for f in done:
                    item = f.get_result()
                    if item and item.next_tag_ts < now:
                        # Update the timestamp. Add a bit of pseudo randomness.
                        item.expiration_ts, item.next_tag_ts = model.expiration_jitter(
                            now, expiration)
                        save_futures.append(item.put_async())
                        saved += 1
                save_futures, _ = _throttle_futures(save_futures, 100)

            for f in save_futures:
                f.get_result()
            logging.info('Timestamped %d entries out of %d', saved,
                         len(digests))
        except Exception as e:
            logging.error('Failed to stamp entries: %s\n%d entries', e,
                          len(digests))
            raise