mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-28 16:12:13 +00:00
service url now is required
This commit is contained in:
parent
872e7407cf
commit
290be9f8bc
@ -43,4 +43,4 @@ class JudgeServerHeartbeatSerializer(serializers.Serializer):
|
||||
memory = serializers.FloatField(min_value=0, max_value=100)
|
||||
cpu = serializers.FloatField(min_value=0, max_value=100)
|
||||
action = serializers.ChoiceField(choices=("heartbeat", ))
|
||||
service_url = serializers.CharField(max_length=256, required=False)
|
||||
service_url = serializers.CharField(max_length=256)
|
||||
|
@ -82,7 +82,7 @@ class JudgeServerHeartbeatTest(APITestCase):
|
||||
def setUp(self):
|
||||
self.url = self.reverse("judge_server_heartbeat_api")
|
||||
self.data = {"hostname": "testhostname", "judger_version": "1.0.4", "cpu_core": 4,
|
||||
"cpu": 90.5, "memory": 80.3, "action": "heartbeat"}
|
||||
"cpu": 90.5, "memory": 80.3, "action": "heartbeat", "service_url": "http://127.0.0.1"}
|
||||
self.token = "test"
|
||||
self.hashed_token = hashlib.sha256(self.token.encode("utf-8")).hexdigest()
|
||||
SysOptions.judge_server_token = self.token
|
||||
@ -93,16 +93,6 @@ class JudgeServerHeartbeatTest(APITestCase):
|
||||
self.assertSuccess(resp)
|
||||
server = JudgeServer.objects.first()
|
||||
self.assertEqual(server.ip, "127.0.0.1")
|
||||
self.assertEqual(server.service_url, None)
|
||||
|
||||
def test_new_heartbeat_service_url(self):
|
||||
service_url = "http://1.2.3.4:8000/api/judge"
|
||||
data = self.data
|
||||
data["service_url"] = service_url
|
||||
resp = self.client.post(self.url, data=self.data, **self.headers)
|
||||
self.assertSuccess(resp)
|
||||
server = JudgeServer.objects.first()
|
||||
self.assertEqual(server.service_url, service_url)
|
||||
|
||||
def test_update_heartbeat(self):
|
||||
self.test_new_heartbeat()
|
||||
|
@ -110,7 +110,6 @@ class JudgeServerHeartbeatAPI(CSRFExemptAPIView):
|
||||
client_token = request.META.get("HTTP_X_JUDGE_SERVER_TOKEN")
|
||||
if hashlib.sha256(SysOptions.judge_server_token.encode("utf-8")).hexdigest() != client_token:
|
||||
return self.error("Invalid token")
|
||||
service_url = data.get("service_url")
|
||||
|
||||
try:
|
||||
server = JudgeServer.objects.get(hostname=data["hostname"])
|
||||
@ -118,7 +117,7 @@ class JudgeServerHeartbeatAPI(CSRFExemptAPIView):
|
||||
server.cpu_core = data["cpu_core"]
|
||||
server.memory_usage = data["memory"]
|
||||
server.cpu_usage = data["cpu"]
|
||||
server.service_url = service_url
|
||||
server.service_url = data["service_url"]
|
||||
server.ip = request.META["HTTP_X_REAL_IP"]
|
||||
server.last_heartbeat = timezone.now()
|
||||
server.save()
|
||||
@ -129,7 +128,7 @@ class JudgeServerHeartbeatAPI(CSRFExemptAPIView):
|
||||
memory_usage=data["memory"],
|
||||
cpu_usage=data["cpu"],
|
||||
ip=request.META["REMOTE_ADDR"],
|
||||
service_url=service_url,
|
||||
service_url=data["service_url"],
|
||||
last_heartbeat=timezone.now(),
|
||||
)
|
||||
# 新server上线 处理队列中的,防止没有新的提交而导致一直waiting
|
||||
|
@ -154,11 +154,7 @@ class JudgeDispatcher(DispatcherBase):
|
||||
|
||||
Submission.objects.filter(id=self.submission.id).update(result=JudgeStatus.JUDGING)
|
||||
|
||||
service_url = server.service_url
|
||||
# not set service_url, it should be a linked container
|
||||
if not service_url:
|
||||
service_url = settings.DEFAULT_JUDGE_SERVER_SERVICE_URL
|
||||
resp = self._request(urljoin(service_url, "/judge"), data=data)
|
||||
resp = self._request(urljoin(server.service_url, "/judge"), data=data)
|
||||
if resp["err"]:
|
||||
self.submission.result = JudgeStatus.COMPILE_ERROR
|
||||
self.submission.statistic_info["err_info"] = resp["data"]
|
||||
|
Loading…
Reference in New Issue
Block a user