tester in docker works
This commit is contained in:
0
Main/management/__init__.py
Normal file
0
Main/management/__init__.py
Normal file
0
Main/management/commands/__init__.py
Normal file
0
Main/management/commands/__init__.py
Normal file
32
Main/management/commands/receive.py
Normal file
32
Main/management/commands/receive.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import pika
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from Main.models import Solution
|
||||
from Sprint import settings
|
||||
from SprintLib.testers import *
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Tests solution'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
print("Enter worker")
|
||||
connection = pika.BlockingConnection(pika.ConnectionParameters(host=settings.RABBIT_HOST))
|
||||
channel = connection.channel()
|
||||
channel.queue_declare(queue='test')
|
||||
|
||||
def callback(ch, method, properties, body):
|
||||
try:
|
||||
id = int(str(body, encoding='utf-8'))
|
||||
print(f"Received id {id}")
|
||||
solution = Solution.objects.get(id=id)
|
||||
except:
|
||||
return
|
||||
try:
|
||||
eval(solution.language.work_name + 'Tester')(solution).execute()
|
||||
except:
|
||||
solution.result = 'TE'
|
||||
solution.save()
|
||||
|
||||
channel.basic_consume(queue='test', on_message_callback=callback, auto_ack=True)
|
||||
channel.start_consuming()
|
15
Main/management/commands/test.py
Normal file
15
Main/management/commands/test.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from Main.models import Solution
|
||||
from SprintLib.testers import *
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Tests solution'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('solution_id', type=int)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
solution = Solution.objects.get(id=options['solution_id'])
|
||||
eval(solution.language.work_name + 'Tester')(solution).execute()
|
8
Main/management/commands/update_languages.py
Normal file
8
Main/management/commands/update_languages.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Updates languages'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
pass
|
@@ -10,7 +10,7 @@ from django.utils import timezone
|
||||
|
||||
from Main.models.task import Task
|
||||
from Main.models.language import Language
|
||||
from Sprint.settings import CONSTS, SOLUTIONS_ROOT
|
||||
from Sprint.settings import CONSTS, SOLUTIONS_ROOT, SOLUTIONS_ROOT_EXTERNAL
|
||||
|
||||
|
||||
class Solution(models.Model):
|
||||
@@ -61,5 +61,9 @@ class Solution(models.Model):
|
||||
def testing_directory(self):
|
||||
return join(self.directory, 'test_dir')
|
||||
|
||||
@property
|
||||
def volume_directory(self):
|
||||
return join(SOLUTIONS_ROOT_EXTERNAL, str(self.id), 'test_dir')
|
||||
|
||||
def exec_command(self, command, working_directory='app', timeout=None):
|
||||
return call(f'docker exec -i solution_{self.id} bash -c "cd {working_directory} && {command}"', shell=True, timeout=timeout)
|
||||
return call(f'docker exec -i solution_{self.id} sh -c "cd {working_directory} && {command}"', shell=True, timeout=timeout)
|
||||
|
@@ -1,9 +0,0 @@
|
||||
from Main.models import Solution
|
||||
from Sprint.celery import app
|
||||
from SprintLib.testers import *
|
||||
|
||||
|
||||
@app.task
|
||||
def start_testing(solution_id):
|
||||
solution = Solution.objects.get(id=solution_id)
|
||||
eval(solution.language.work_name + 'Tester')(solution).execute()
|
@@ -1,8 +1,8 @@
|
||||
from zipfile import ZipFile
|
||||
|
||||
from Main.models import Solution, Progress
|
||||
from Main.tasks import start_testing
|
||||
from Main.models import Solution
|
||||
from SprintLib.BaseView import BaseView, Language
|
||||
from SprintLib.queue import send_testing
|
||||
from SprintLib.testers import *
|
||||
|
||||
|
||||
@@ -31,11 +31,13 @@ class TaskView(BaseView):
|
||||
file_path = join(self.solution.directory, filename)
|
||||
with open(file_path, 'w') as fs:
|
||||
fs.write(self.request.POST['code'])
|
||||
start_testing.delay(self.solution.id)
|
||||
send_testing(self.solution.id)
|
||||
return "task?task_id=" + str(self.entities.task.id)
|
||||
|
||||
def post_1(self):
|
||||
# отправка решения через файл
|
||||
if 'file' not in self.request.FILES:
|
||||
return "task?task_id=" + str(self.entities.task.id)
|
||||
filename = self.request.FILES['file'].name
|
||||
file_path = join(self.solution.directory, filename)
|
||||
with open(file_path, 'wb') as fs:
|
||||
@@ -44,5 +46,5 @@ class TaskView(BaseView):
|
||||
if filename.endswith('.zip'):
|
||||
with ZipFile(file_path) as obj:
|
||||
obj.extractall(self.solution.directory)
|
||||
start_testing.delay(self.solution.id)
|
||||
send_testing(self.solution.id)
|
||||
return "task?task_id=" + str(self.entities.task.id)
|
||||
|
Reference in New Issue
Block a user