2015-06-26 07:59:53 +00:00
|
|
|
from django.db import models
|
2017-01-24 05:22:12 +00:00
|
|
|
from django.utils import timezone
|
2015-06-26 07:59:53 +00:00
|
|
|
|
2016-09-25 09:00:52 +00:00
|
|
|
|
2016-11-20 11:18:25 +00:00
|
|
|
class JudgeServer(models.Model):
|
2018-05-01 04:54:27 +00:00
|
|
|
hostname = models.TextField()
|
|
|
|
ip = models.TextField(null=True)
|
|
|
|
judger_version = models.TextField()
|
2016-11-20 11:18:25 +00:00
|
|
|
cpu_core = models.IntegerField()
|
|
|
|
memory_usage = models.FloatField()
|
|
|
|
cpu_usage = models.FloatField()
|
|
|
|
last_heartbeat = models.DateTimeField()
|
|
|
|
create_time = models.DateTimeField(auto_now_add=True)
|
|
|
|
task_number = models.IntegerField(default=0)
|
2018-05-01 04:54:27 +00:00
|
|
|
service_url = models.TextField(null=True)
|
2017-12-24 04:10:02 +00:00
|
|
|
is_disabled = models.BooleanField(default=False)
|
2016-11-20 11:18:25 +00:00
|
|
|
|
2017-01-24 05:22:12 +00:00
|
|
|
@property
|
|
|
|
def status(self):
|
2017-05-10 09:20:52 +00:00
|
|
|
# 增加一秒延时,提高对网络环境的适应性
|
|
|
|
if (timezone.now() - self.last_heartbeat).total_seconds() > 6:
|
2017-01-24 05:22:12 +00:00
|
|
|
return "abnormal"
|
|
|
|
return "normal"
|
|
|
|
|
2016-11-20 11:18:25 +00:00
|
|
|
class Meta:
|
|
|
|
db_table = "judge_server"
|