class Command(BaseCommand): help = "Remove all vcs data ingested by Perfherder" # max runtime PER_DELETE_SPRINT = timedelta(minutes=5) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.__timer = MaxRuntime(self.PER_DELETE_SPRINT) self.__timer.start_timer() def handle(self, *args, **options): vcs_signatures = PerformanceSignature.objects.filter( framework__name='vcs') for signature in vcs_signatures: signature.delete() # intentionally cascades to data points also self._maybe_take_small_break( ) # so database won't cripple; blocking call def _maybe_take_small_break(self): if self.__enough_work(): time.sleep(10) def __enough_work(self) -> bool: try: self.__timer.quit_on_timeout() # check timer except MaxRuntimeExceeded: self.__timer.start_timer() # reset & restart it return True return False
def test_performance_cycler_quit_indicator(mock_taskcluster_notify): ten_minutes_ago = datetime.now() - timedelta(minutes=10) one_second = timedelta(seconds=1) two_seconds_ago = datetime.now() - timedelta(seconds=2) five_minutes = timedelta(minutes=5) with pytest.raises(MaxRuntimeExceeded): PerfherderCycler(chunk_size=100, sleep_time=0) max_runtime = MaxRuntime(max_runtime=one_second) max_runtime.started_at = ten_minutes_ago max_runtime.quit_on_timeout() try: PerfherderCycler(chunk_size=100, sleep_time=0) max_runtime = MaxRuntime(max_runtime=five_minutes) max_runtime.started_at = two_seconds_ago max_runtime.quit_on_timeout() except MaxRuntimeExceeded: pytest.fail('Performance cycling shouldn\'t have timed out')