mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-04 03:22:06 +00:00
完成服务器判题队列长度监控功能
This commit is contained in:
parent
9879195555
commit
d8dd9cd72c
@ -10,12 +10,6 @@ from settings import docker_config, source_code_dir, test_case_dir, submission_d
|
||||
|
||||
@app.task
|
||||
def judge(submission_id, time_limit, memory_limit, test_case_id):
|
||||
# 先更新判题队列长度
|
||||
r = redis.StrictRedis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
|
||||
length = r.incr("queue_length")
|
||||
now = datetime.datetime.now()
|
||||
# 使用hash key是今天的日期 value 的 key 是当前时分秒 12:02:03 value 是队列长度
|
||||
r.hset(str(datetime.date.today()), ":".join([str(now.hour), str(now.minute), str(now.second)]), length)
|
||||
try:
|
||||
command = "%s run -t -i --privileged --rm=true " \
|
||||
"-v %s:/var/judger/test_case/ " \
|
||||
@ -42,8 +36,4 @@ def judge(submission_id, time_limit, memory_limit, test_case_id):
|
||||
cur.execute("update submission set result=%s, info=%s where id=%s",
|
||||
(result["system_error"], str(e), submission_id))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
r.decr("queue_length")
|
||||
now = datetime.datetime.now()
|
||||
# 使用hash key是今天的日期 value 的 key 是当前时分秒 12:02:03 value 是队列长度
|
||||
r.hset(str(datetime.date.today()), ":".join([str(now.hour), str(now.minute), str(now.second)]), length)
|
||||
conn.close()
|
0
monitor/__init__.py
Normal file
0
monitor/__init__.py
Normal file
15
monitor/views.py
Normal file
15
monitor/views.py
Normal file
@ -0,0 +1,15 @@
|
||||
# coding=utf-8
|
||||
import redis
|
||||
import datetime
|
||||
from rest_framework.views import APIView
|
||||
from judge.judger.result import result
|
||||
from utils.shortcuts import success_response
|
||||
from submission.models import Submission
|
||||
|
||||
|
||||
class QueueLengthMonitorAPIView(APIView):
|
||||
def get(self, request):
|
||||
waiting_number = Submission.objects.filter(result=result["waiting"]).count()
|
||||
now = datetime.datetime.now()
|
||||
return success_response({"time": ":".join([str(now.hour), str(now.minute), str(now.second)]),
|
||||
"count": waiting_number})
|
@ -15,6 +15,7 @@ from admin.views import AdminTemplateView
|
||||
|
||||
from problem.views import TestCaseUploadAPIView, ProblemTagAdminAPIView, ProblemAdminAPIView
|
||||
from submission.views import SubmissionAPIView, SubmissionAdminAPIView
|
||||
from monitor.views import QueueLengthMonitorAPIView
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
@ -58,5 +59,6 @@ urlpatterns = [
|
||||
name="join_group_request_admin_api"),
|
||||
url(r'^api/submission/$', SubmissionAPIView.as_view(), name="submission_api"),
|
||||
url(r'^api/admin/submission/$', SubmissionAdminAPIView.as_view(), name="submission_admin_api_view"),
|
||||
url(r'^api/admin/monitor/$', QueueLengthMonitorAPIView.as_view(), name="queue_length_monitor_api"),
|
||||
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user