Пример #1
0
    def testQueueStatsUpdates(self):
        j = job.Job.New((), (),
                        arguments={'configuration': 'mock'},
                        comparison_mode='performance')
        scheduler.Schedule(j)
        j.Start = mock.MagicMock(side_effect=j._Complete)

        # Check that we can find the queued job.
        stats = scheduler.QueueStats('mock')
        self.assertEquals(stats['queued_jobs'], 1)
        self.assertNotIn('running_jobs', stats)
        self.assertEquals(len(stats['queue_time_samples']), 0)

        response = self.testapp.get('/cron/fifo-scheduler')
        self.assertEqual(response.status_code, 200)

        self.ExecuteDeferredTasks('default')

        self.assertTrue(j.Start.called)
        job_id, _ = scheduler.PickJobs('mock')[0]
        self.assertIsNone(job_id)

        # Check that point-in-time stats are zero, and that we have one sample.
        stats = scheduler.QueueStats('mock')
        self.assertNotIn('queued_jobs', stats)
        self.assertNotIn('running_jobs', stats)
        self.assertNotEquals(len(stats['queue_time_samples']), 0)
        self.assertEquals(len(stats['queue_time_samples'][0]), 2)
Пример #2
0
    def get(self, configuration):
        if not configuration:
            self.response.set_status(400)
            self.response.write(
                json.dumps({'error': 'Missing configuration in request.'}))
            return

        queue_stats = scheduler.QueueStats(configuration)
        self.response.write(json.dumps(queue_stats))
Пример #3
0
  def _GetRunTimeEstimate(self):
    result = timing_record.GetSimilarHistoricalTimings(self)
    if not result:
      return {}

    timings = [t.total_seconds() for t in result.timings]
    return {
        'estimate': {'timings': timings, 'tags': result.tags},
        'queue_stats': scheduler.QueueStats(self.configuration)
    }
Пример #4
0
    def testJobSamplesCapped(self):
        for _ in range(51):
            j = job.Job.New((), (),
                            arguments={'configuration': 'mock'},
                            comparison_mode='performance')
            scheduler.Schedule(j)
            j.Start = mock.MagicMock(side_effect=j._Complete)
            response = self.testapp.get('/cron/fifo-scheduler')
            self.assertEqual(response.status_code, 200)

        self.ExecuteDeferredTasks('default')

        stats = scheduler.QueueStats('mock')
        self.assertLessEqual(len(stats.get('queue_time_samples')), 50)
Пример #5
0
    def PostCreationUpdate(self):
        pending = 0
        if self.configuration:
            try:
                pending = scheduler.QueueStats(self.configuration).get(
                    'queued_jobs', 0)
            except (scheduler.QueueNotFound, ndb.BadRequestError) as e:
                logging.warning(
                    'Error encountered fetching queue named "%s": %s ',
                    self.configuration, e)

        bug_update = job_bug_update.JobUpdateBuilder(self).CreationUpdate(
            pending)
        deferred.defer(_PostBugCommentDeferred,
                       self.bug_id,
                       bug_update.comment_text,
                       project=self.project,
                       send_email=True,
                       _retry_options=RETRY_OPTIONS)
Пример #6
0
  def PostCreationUpdate(self):
    title = _ROUND_PUSHPIN + ' Pinpoint job created and queued.'
    pending = 0
    if self.configuration:
      try:
        pending = scheduler.QueueStats(self.configuration).get('queued_jobs', 0)
      except (scheduler.QueueNotFound, ndb.BadRequestError) as e:
        logging.warning('Error encountered fetching queue named "%s": %s ',
                        self.configuration, e)

    comment = CREATED_COMMENT_FORMAT.format(
        title=title,
        url=self.url,
        configuration=self.configuration if self.configuration else '(None)',
        pending=pending)
    deferred.defer(
        _PostBugCommentDeferred,
        self.bug_id,
        comment,
        send_email=True,
        _retry_options=RETRY_OPTIONS)