OnlineJudge/conf/models.py

26 lines
878 B
Python
Raw Normal View History

from django.db import models
2017-01-24 05:22:12 +00:00
from django.utils import timezone
2016-09-25 09:00:52 +00:00
2016-11-20 11:18:25 +00:00
class JudgeServer(models.Model):
2017-10-01 21:16:14 +00:00
hostname = models.CharField(max_length=128)
2016-11-20 11:18:25 +00:00
ip = models.CharField(max_length=32, blank=True, null=True)
2017-10-01 21:16:14 +00:00
judger_version = models.CharField(max_length=32)
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)
2017-10-01 21:16:14 +00:00
service_url = models.CharField(max_length=256, blank=True, null=True)
2016-11-20 11:18:25 +00:00
2017-01-24 05:22:12 +00:00
@property
def status(self):
# 增加一秒延时,提高对网络环境的适应性
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"