def testJobCancellationSucceedsOnRunningJob(self): j = job.Job.New((), (), arguments={'configuration': 'mock'}, comparison_mode='performance') scheduler.Schedule(j) j.Start = mock.MagicMock() response = self.testapp.get('/cron/fifo-scheduler') self.assertEqual(response.status_code, 200) self.ExecuteDeferredTasks('default') self.assertTrue(j.Start.called) # Ensure that the job is still running. job_id, queue_status = scheduler.PickJobs('mock')[0] self.assertEqual(job_id, j.job_id) self.assertEqual(queue_status, 'Running') # We can cancel a running job. self.assertTrue(scheduler.Cancel(j)) # Ensure that the job is still running. job_id, queue_status = scheduler.PickJobs('mock')[0] self.assertNotEqual(job_id, j.job_id) self.assertNotEqual(queue_status, 'Running')
def Cancel(self, user, reason): # We cannot cancel an already cancelled job. if self.cancelled: logging.warning( 'Attempted to cancel a cancelled job "%s"; user = %s, reason = %s', self.job_id, user, reason) raise errors.CancelError('Job already cancelled.') if not scheduler.Cancel(self): raise errors.CancelError('Scheduler failed to cancel job.') self.cancelled = True self.cancel_reason = '{}: {}'.format(user, reason) # Remove any "task" identifiers. self.task = None self.put() title = _ROUND_PUSHPIN + ' Pinpoint job cancelled.' comment = u'{}\n{}\n\nCancelled by {}, reason given: {}'.format( title, self.url, user, reason) deferred.defer(_PostBugCommentDeferred, self.bug_id, comment, send_email=False, _retry_options=RETRY_OPTIONS)
def testJobCancellationSucceedsOnQueuedJob(self): j = job.Job.New((), (), arguments={'configuration': 'mock'}, comparison_mode='performance') scheduler.Schedule(j) j.Start = mock.MagicMock() self.assertTrue(scheduler.Cancel(j)) response = self.testapp.get('/cron/fifo-scheduler') self.assertEqual(response.status_code, 200) self.ExecuteDeferredTasks('default') self.assertFalse(j.Start.called)