2020-07-19 21:27:14 +00:00
|
|
|
import logging
|
|
|
|
import signal
|
|
|
|
import threading
|
|
|
|
from functools import partial
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
from judge.bridge.django_handler import DjangoHandler
|
|
|
|
from judge.bridge.judge_handler import JudgeHandler
|
|
|
|
from judge.bridge.judge_list import JudgeList
|
|
|
|
from judge.bridge.server import Server
|
|
|
|
from judge.models import Judge, Submission
|
|
|
|
|
2022-05-14 17:57:27 +00:00
|
|
|
logger = logging.getLogger("judge.bridge")
|
2020-07-19 21:27:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def reset_judges():
|
|
|
|
Judge.objects.update(online=False, ping=None, load=None)
|
|
|
|
|
|
|
|
|
|
|
|
def judge_daemon():
|
|
|
|
reset_judges()
|
2022-05-14 17:57:27 +00:00
|
|
|
Submission.objects.filter(status__in=Submission.IN_PROGRESS_GRADING_STATUS).update(
|
|
|
|
status="IE", result="IE", error=None
|
|
|
|
)
|
2020-07-19 21:27:14 +00:00
|
|
|
judges = JudgeList()
|
|
|
|
|
2022-05-14 17:57:27 +00:00
|
|
|
judge_server = Server(
|
|
|
|
settings.BRIDGED_JUDGE_ADDRESS, partial(JudgeHandler, judges=judges)
|
|
|
|
)
|
|
|
|
django_server = Server(
|
|
|
|
settings.BRIDGED_DJANGO_ADDRESS, partial(DjangoHandler, judges=judges)
|
|
|
|
)
|
2020-07-19 21:27:14 +00:00
|
|
|
|
|
|
|
threading.Thread(target=django_server.serve_forever).start()
|
|
|
|
threading.Thread(target=judge_server.serve_forever).start()
|
|
|
|
|
|
|
|
stop = threading.Event()
|
|
|
|
|
|
|
|
def signal_handler(signum, _):
|
2022-05-14 17:57:27 +00:00
|
|
|
logger.info("Exiting due to %s", signal.Signals(signum).name)
|
2020-07-19 21:27:14 +00:00
|
|
|
stop.set()
|
|
|
|
|
|
|
|
signal.signal(signal.SIGINT, signal_handler)
|
|
|
|
signal.signal(signal.SIGQUIT, signal_handler)
|
|
|
|
signal.signal(signal.SIGTERM, signal_handler)
|
|
|
|
|
|
|
|
try:
|
|
|
|
stop.wait()
|
|
|
|
finally:
|
|
|
|
django_server.shutdown()
|
|
|
|
judge_server.shutdown()
|