From 95c5fef9ed92d430b7df1afc7b09a7d5db9a2640 Mon Sep 17 00:00:00 2001 From: Egor Matveev Date: Sat, 7 May 2022 21:49:20 +0300 Subject: [PATCH] solution_id --- daemons/management/commands/docker_cleaner.py | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/daemons/management/commands/docker_cleaner.py b/daemons/management/commands/docker_cleaner.py index f029d27..faff1e0 100644 --- a/daemons/management/commands/docker_cleaner.py +++ b/daemons/management/commands/docker_cleaner.py @@ -10,6 +10,7 @@ class Command(LoopWorker): def go(self): result = run("docker ps", universal_newlines=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True) lines = result.stdout.split('\n')[1:] + solution_id = None for line in lines: line = [i for i in line.split() if i] if line and line[-1].startswith('solution_'): @@ -17,10 +18,12 @@ class Command(LoopWorker): if el.isnumeric(): solution_id = int(el) break - solution = Solution.objects.filter(id=solution_id).first() - if solution is not None and (solution.result == 'In queue' or solution.result == 'Testing'): - continue + if solution_id: + solution = Solution.objects.filter(id=solution_id).first() + if solution is not None and (solution.result == 'In queue' or solution.result == 'Testing'): + continue call(f"docker rm --force {line[-1]}", shell=True) + solution_id = None result = run("docker image ls", universal_newlines=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True) lines = result.stdout.split('\n')[1:] for line in lines: @@ -30,10 +33,12 @@ class Command(LoopWorker): if el.isnumeric(): solution_id = int(el) break - solution = Solution.objects.filter(id=solution_id).first() - if solution is not None and (solution.result == 'In queue' or solution.result == 'Testing'): - continue + if solution_id: + solution = Solution.objects.filter(id=solution_id).first() + if solution is not None and (solution.result == 'In queue' or solution.result == 'Testing'): + continue call("docker image rm " + line[0], shell=True) + solution_id = None result = run("docker network ls", universal_newlines=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True) lines = result.stdout.split('\n')[1:] for line in lines: @@ -43,9 +48,10 @@ class Command(LoopWorker): if el.isnumeric(): solution_id = int(el) break - solution = Solution.objects.filter(id=solution_id).first() - if solution is not None and (solution.result == 'In queue' or solution.result == 'Testing'): - continue + if solution_id: + solution = Solution.objects.filter(id=solution_id).first() + if solution is not None and (solution.result == 'In queue' or solution.result == 'Testing'): + continue call("docker network rm " + line[0], shell=True) a = 5 a += 1