no docker cleaner

This commit is contained in:
Egor Matveev
2022-05-25 08:48:19 +03:00
parent 3734ad0354
commit 8ac97d3dd2
5 changed files with 0 additions and 171 deletions

View File

@@ -1,40 +0,0 @@
from subprocess import call
from SprintLib.redis import lock, get_redis
from SprintLib.utils import LoopWorker
class Command(LoopWorker):
help = "starts docker cleaner"
@lock("docker")
def go(self):
containers, images, networks = list(), list(), list()
with get_redis() as r:
while r.llen("containers") != 0:
value = r.rpop("containers").decode("utf-8")
return_code = call(f"docker rm --force {value}", shell=True)
if return_code != 0:
containers.append(value)
while r.llen("images") != 0:
value = r.rpop("images").decode("utf-8")
return_code = call(f"docker image rm --force {value}", shell=True)
if return_code != 0:
images.append(value)
while r.llen("networks") != 0:
value = r.rpop("networks").decode("utf-8")
return_code = call(f"docker network rm {value}", shell=True)
if return_code != 0:
networks.append(value)
if containers:
r.lpush("containers", *containers)
if images:
r.lpush("images", *images)
if networks:
r.lpush("networks", *networks)
def handle(self, *args, **options):
call('docker image rm $(docker images -q mathwave/sprint-repo)', shell=True)
print("Old images removed")
super().handle(*args, **options)

View File

@@ -1,29 +0,0 @@
from SprintLib.queue import MessagingSupport
from SprintLib.redis import lock, get_redis
class Command(MessagingSupport):
help = "Starts redis worker"
queue_name = "redis"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.handlers = {
"docker": self.docker_handler
}
@lock("docker")
def docker_handler(self, payload):
key = payload["key"]
value = payload["value"]
with get_redis() as r:
r.lpush(key, value)
def process(self, payload: dict):
action = payload.get("action")
if action is None:
raise ValueError("No action field in message")
handler = self.handlers.get(action)
if handler is None:
raise ValueError(f"No handler for action: {action}")
handler(payload)