This commit is contained in:
Egor Matveev 2022-04-01 19:35:17 +03:00
parent 022f8bcb4d
commit b2eaa094b3
2 changed files with 17 additions and 3 deletions

View File

@ -178,7 +178,7 @@ class BaseTester:
add_name = file.filename[11:]
send_to_queue("cleaner", {"type": "container", "name": f"solution_container_{self.solution.id}_{add_name}"})
send_to_queue("cleaner", {"type": "image", "name": f"solution_image_{self.solution.id}_{add_name}"})
send_to_queue("cleaner", {"type": "network", "name": f"docker network rm solution_network_{self.solution.id}"})
send_to_queue("cleaner", {"type": "network", "name": f"solution_network_{self.solution.id}"})
self.solution.user.userinfo.refresh_from_db()
notify(
self.solution.user,

View File

@ -8,5 +8,19 @@ class Command(MessagingSupport):
queue_name = "cleaner"
def process(self, payload: dict):
call(f'docker {payload["type"]} rm --force {payload["name"]}', shell=True)
print(f"Removed {payload['type']} {payload['name']}")
name = payload['name']
type = payload['type']
if type == 'network':
command = f'docker network rm {name}'
elif type == 'container':
command = f'docker rm --force {name}'
elif type == 'image':
command = f'docker image rm --force {name}'
else:
raise NotImplementedError(f"Unknown type {type}")
print(f"Executing command {command}")
code = call(command, shell=True)
if code == 0:
print(f"Removed {type} {name}")
else:
print("Something went wrong")