Exemple #1
0
  def get(self):
    extra = frozenset(self.request.GET) - self.EXPECTED
    if extra:
      self.abort_with_error(
          400,
          error='Extraneous query parameters. Did you make a typo? %s' %
          ','.join(sorted(extra)))

    interval = self.request.get('interval', 24 * 3600)
    state = self.request.get('state', 'all')
    tags = self.request.get_all('tag')

    try:
      interval = int(interval)
      if interval <= 0:
        raise ValueError()
    except ValueError:
      self.abort_with_error(
          400, error='"interval" must be a positive integer number of seconds')

    if state not in self.VALID_STATES:
      self.abort_with_error(
          400,
          error='Invalid state "%s", expecting on of %s' %
          (state, ', '.join(sorted(self.VALID_STATES))))

    # Cutoff deadline => request key for filtering (it embeds timestamp).
    cutoff = utils.utcnow() - datetime.timedelta(seconds=interval)
    request_id = task_request.datetime_to_request_base_id(cutoff)
    request_key = task_request.request_id_to_key(request_id)

    query = task_result.get_result_summary_query(None, state, tags)
    query = query.filter(task_result.TaskResultSummary.key <= request_key)
    self.send_response(utils.to_json_encodable({'count': query.count()}))
Exemple #2
0
  def get(self):
    extra = frozenset(self.request.GET) - self.EXPECTED
    if extra:
      self.abort_with_error(
          400,
          error='Extraneous query parameters. Did you make a typo? %s' %
          ','.join(sorted(extra)))

    interval = self.request.get('interval', 24 * 3600)
    state = self.request.get('state', 'all')
    tags = self.request.get_all('tag')

    try:
      interval = int(interval)
      if interval <= 0:
        raise ValueError()
    except ValueError:
      self.abort_with_error(
          400, error='"interval" must be a positive integer number of seconds')

    if state not in self.VALID_STATES:
      self.abort_with_error(
          400,
          error='Invalid state "%s", expecting on of %s' %
          (state, ', '.join(sorted(self.VALID_STATES))))

    # Cutoff deadline => request key for filtering (it embeds timestamp).
    cutoff = utils.utcnow() - datetime.timedelta(seconds=interval)
    request_id = task_request.datetime_to_request_base_id(cutoff)
    request_key = task_request.request_id_to_key(request_id)

    query = task_result.get_result_summary_query(None, state, tags)
    query = query.filter(task_result.TaskResultSummary.key <= request_key)
    self.send_response(utils.to_json_encodable({'count': query.count()}))
Exemple #3
0
 def _get_counts_future(self, now):
     """Returns all the counting futures in parallel."""
     counts_future = {}
     last_24h = now - datetime.timedelta(days=1)
     request_id = task_request.datetime_to_request_base_id(last_24h)
     request_key = task_request.request_id_to_key(request_id)
     for state_key, _, _ in itertools.chain.from_iterable(self.STATE_CHOICES):
         query = task_result.get_result_summary_query(None, state_key, None)
         # It is counter intuitive but the equality has to be reversed, since the
         # value in the db is binary negated.
         counts_future[state_key] = query.filter(task_result.TaskResultSummary.key <= request_key).count_async()
     return counts_future
 def _get_counts_future(self, now):
     """Returns all the counting futures in parallel."""
     counts_future = {}
     last_24h = now - datetime.timedelta(days=1)
     request_id = task_request.datetime_to_request_base_id(last_24h)
     request_key = task_request.request_id_to_key(request_id)
     for state_key, _, _ in itertools.chain.from_iterable(
             self.STATE_CHOICES):
         query = task_result.get_result_summary_query(None, state_key)
         # It is counter intuitive but the equality has to be reversed, since the
         # value in the db is binary negated.
         counts_future[state_key] = query.filter(
             task_result.TaskResultSummary.key <= request_key).count_async(
             )
     return counts_future