testers
This commit is contained in:
parent
a47563d7c1
commit
2ee9f1ea3b
@ -3,6 +3,7 @@ from shutil import rmtree
|
|||||||
|
|
||||||
import pika
|
import pika
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
from pika.adapters.utils.connection_workflow import AMQPConnectionWorkflowFailed
|
||||||
|
|
||||||
from Main.models import Solution
|
from Main.models import Solution
|
||||||
from Sprint import settings
|
from Sprint import settings
|
||||||
@ -14,26 +15,30 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
print("Enter worker")
|
print("Enter worker")
|
||||||
connection = pika.BlockingConnection(
|
while True:
|
||||||
pika.ConnectionParameters(host=settings.RABBIT_HOST)
|
|
||||||
)
|
|
||||||
channel = connection.channel()
|
|
||||||
channel.queue_declare(queue="test")
|
|
||||||
|
|
||||||
def callback(ch, method, properties, body):
|
|
||||||
id = int(str(body, encoding="utf-8"))
|
|
||||||
print(f"Received id {id}")
|
|
||||||
solution = Solution.objects.get(id=id)
|
|
||||||
try:
|
try:
|
||||||
eval(solution.language.work_name + "Tester")(solution).execute()
|
connection = pika.BlockingConnection(
|
||||||
except Exception as e:
|
pika.ConnectionParameters(host=settings.RABBIT_HOST)
|
||||||
print(e)
|
)
|
||||||
solution.result = "TE"
|
channel = connection.channel()
|
||||||
solution.save()
|
channel.queue_declare(queue="test")
|
||||||
finally:
|
|
||||||
path = join("solutions", str(id))
|
|
||||||
if exists(path):
|
|
||||||
rmtree(path)
|
|
||||||
|
|
||||||
channel.basic_consume(queue="test", on_message_callback=callback, auto_ack=True)
|
def callback(ch, method, properties, body):
|
||||||
channel.start_consuming()
|
id = int(str(body, encoding="utf-8"))
|
||||||
|
print(f"Received id {id}")
|
||||||
|
solution = Solution.objects.get(id=id)
|
||||||
|
try:
|
||||||
|
eval(solution.language.work_name + "Tester")(solution).execute()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
solution.result = "TE"
|
||||||
|
solution.save()
|
||||||
|
finally:
|
||||||
|
path = join("solutions", str(id))
|
||||||
|
if exists(path):
|
||||||
|
rmtree(path)
|
||||||
|
|
||||||
|
channel.basic_consume(queue="test", on_message_callback=callback, auto_ack=True)
|
||||||
|
channel.start_consuming()
|
||||||
|
except AMQPConnectionWorkflowFailed:
|
||||||
|
print("connection to rabbit failed: reconnecting")
|
||||||
|
Loading…
Reference in New Issue
Block a user