dev test
This commit is contained in:
1
judge_dispatcher/__init__.py
Normal file
1
judge_dispatcher/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# coding=utf-8
|
||||
16
judge_dispatcher/judge.py
Normal file
16
judge_dispatcher/judge.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# coding=utf-8
|
||||
import socket
|
||||
import redis
|
||||
|
||||
from .rpc_client import TimeoutServerProxy
|
||||
from .settings import redis_config
|
||||
from .models import JudgeServer
|
||||
|
||||
|
||||
class JudgeDispatcher(object):
|
||||
def __init__(self):
|
||||
self.redis = redis.StrictRedis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
|
||||
|
||||
def judge(self):
|
||||
pass
|
||||
|
||||
15
judge_dispatcher/models.py
Normal file
15
judge_dispatcher/models.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# coding=utf-8
|
||||
from django.db import models
|
||||
|
||||
|
||||
class JudgeServer(models.Model):
|
||||
ip = models.IPAddressField()
|
||||
port = models.IntegerField()
|
||||
# 这个服务器最大可能运行的判题实例数量
|
||||
max_instance_number = models.IntegerField()
|
||||
left_instance_number = models.IntegerField()
|
||||
# status 为 false 的时候代表不使用这个服务器
|
||||
status = models.BooleanField(default=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "judge_server"
|
||||
24
judge_dispatcher/rpc_client.py
Normal file
24
judge_dispatcher/rpc_client.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# coding=utf-8
|
||||
import xmlrpclib
|
||||
import httplib
|
||||
|
||||
|
||||
class TimeoutHTTPConnection(httplib.HTTPConnection):
|
||||
def __init__(self, host, timeout=10):
|
||||
httplib.HTTPConnection.__init__(self, host, timeout=timeout)
|
||||
|
||||
|
||||
class TimeoutTransport(xmlrpclib.Transport):
|
||||
def __init__(self, timeout=10, *args, **kwargs):
|
||||
xmlrpclib.Transport.__init__(self, *args, **kwargs)
|
||||
self.timeout = timeout
|
||||
|
||||
def make_connection(self, host):
|
||||
conn = TimeoutHTTPConnection(host, self.timeout)
|
||||
return conn
|
||||
|
||||
|
||||
class TimeoutServerProxy(xmlrpclib.ServerProxy):
|
||||
def __init__(self, uri, timeout=10, *args, **kwargs):
|
||||
kwargs['transport'] = TimeoutTransport(timeout=timeout, use_datetime=kwargs.get('use_datetime', 0))
|
||||
xmlrpclib.ServerProxy.__init__(self, uri, *args, **kwargs)
|
||||
9
judge_dispatcher/settings.py
Normal file
9
judge_dispatcher/settings.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# coding=utf-8
|
||||
import os
|
||||
|
||||
|
||||
redis_config = {
|
||||
"host": os.environ.get("REDIS_PORT_6379_TCP_ADDR"),
|
||||
"port": 6379,
|
||||
"db": 0
|
||||
}
|
||||
Reference in New Issue
Block a user