Redis
This commit is contained in:
28
SprintLib/redis.py
Normal file
28
SprintLib/redis.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
|
||||
import redis
|
||||
|
||||
|
||||
def get_redis():
|
||||
return redis.Redis(host=os.getenv("REDIS_HOST", "127.0.0.1"))
|
||||
|
||||
|
||||
def get(key):
|
||||
with get_redis() as r:
|
||||
return r.get(key)
|
||||
|
||||
|
||||
def set(key, value):
|
||||
with get_redis() as r:
|
||||
return r.set(key, value)
|
||||
|
||||
|
||||
def lock(name='lock'):
|
||||
def dec(fun):
|
||||
def wrapper(*args, **kwargs):
|
||||
with get_redis() as r:
|
||||
with r.lock(name):
|
||||
return fun(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
return dec
|
@@ -5,7 +5,7 @@ from tempfile import TemporaryDirectory
|
||||
|
||||
from Main.models.progress import Progress
|
||||
from Sprint.settings import CONSTS
|
||||
from SprintLib.queue import notify
|
||||
from SprintLib.queue import notify, send_to_queue
|
||||
from SprintLib.utils import Timer
|
||||
|
||||
|
||||
@@ -132,6 +132,14 @@ class BaseTester:
|
||||
|
||||
def cleanup(self):
|
||||
self.solution.save()
|
||||
send_to_queue("redis", {"action": "docker", "key": "containers", "value": f"solution_{self.solution.id}"})
|
||||
if self.checker_code:
|
||||
send_to_queue("redis", {"action": "docker", "key": "containers", "value": f"solution_{self.solution.id}_checker"})
|
||||
for file in self.solution.task.dockerfiles:
|
||||
add_name = file.filename[11:]
|
||||
send_to_queue("redis", {"action": "docker", "key": "containers", "value": f"solution_container_{self.solution.id}_{add_name}"})
|
||||
send_to_queue("redis", {"action": "docker", "key": "images", "value": f"solution_image_{self.solution.id}_{add_name}"})
|
||||
send_to_queue("redis", {"action": "docker", "key": "networks", "value": f"solution_network_{self.solution.id}"})
|
||||
|
||||
def save_progress(self):
|
||||
progress = Progress.objects.get(
|
||||
|
Reference in New Issue
Block a user