Exemplo n.º 1
0
    def clear(self, request):
        """clear dead results and reset tasks, will be called async when user visit run detail page."""
        pending_resets = ResetResult.objects.filter(reset_status__lt=2)  # none, in progress
        fixed = []

        for result in pending_resets:
            delta = datetime.now(timezone.utc) - result.reset_on
            if delta.days > 1:
                logger.info('abort reset result: {}'.format(result.id))
                result.outcome, result.reset_status = 1, 3  # failed, failed
                result.stdout = 'Reset task timeout.'
                result.save()
                fixed.append(result.id)

        return Response(data=fixed)
Exemplo n.º 2
0
    def clear(self, request):
        """clear dead tasks, will be called async when user visit run detail page."""

        pending_tasks = Task.objects.filter(status=-1)  # pending
        fixed = []

        for task in pending_tasks:
            delta = datetime.now(timezone.utc) - task.updated_on
            if delta.days > 1:
                logger.info('abort task: {}'.format(task.id))
                task.status = 1
                task.data = append_json(task.data, 'error', '\nTask timeout, auto clear.')
                task.save()
                fixed.append(task.id)

        return Response(data=fixed)
Exemplo n.º 3
0
    def clear(self, request):
        """clear dead runs, will be called async when user visit run list."""
        pending_runs = TestRun.objects.filter(state__lt=2)  # not ready, starting, running
        fixed = []

        for run in pending_runs:
            delta = datetime.now(timezone.utc) - run.start_time
            if delta.days > 1 and run.state < 2:
                logger.info('abort run: {}'.format(run.id))
                run.state, run.status = 2, 1  # abort, failed
                run.save()
                fixed.append(run.id)

        bad_runs = TestRun.objects.filter(results=None)  # run without results > 2 days
        for run in bad_runs:
            if (datetime.now(tz=timezone.utc) - run.start_time).days >= 2:
                logger.info('delete run: {}'.format(run.id))
                fixed.append(run.id)
                run.delete()

        return Response(data=fixed)
Exemplo n.º 4
0
    def cleanup(self, request):
        """cleanup runs = delete old runs via config value."""
        if 'days' in request.GET:
            days = int(request.GET.get('days'))
        else:
            days = get_auto_cleanup_run_days()

        if days <= 0:
            return Response(data=[])

        logger.info('clean up runs before {} days'.format(days))
        time_threshold = datetime.now(tz=timezone.utc) - timedelta(days=days)
        pending_runs = TestRun.objects.filter(start_time__lt=time_threshold)
        fixed = []

        for run in pending_runs:
            logger.info('delete old run: {}'.format(run.id))
            cleanup_run_media(run.id)
            fixed.append(run.id)
            run.delete()

        return Response(data=fixed)