add judge server status field

This commit is contained in:
virusdefender 2017-01-24 13:22:12 +08:00
parent d1e505dc24
commit 0fe5b10418
2 changed files with 8 additions and 0 deletions

View File

@ -1,4 +1,5 @@
from django.db import models
from django.utils import timezone
class SMTPConfig(models.Model):
@ -38,6 +39,12 @@ class JudgeServer(models.Model):
task_number = models.IntegerField(default=0)
service_url = models.CharField(max_length=128, blank=True, null=True)
@property
def status(self):
if (timezone.now() - self.last_heartbeat).total_seconds() > 5:
return "abnormal"
return "normal"
class Meta:
db_table = "judge_server"

View File

@ -43,6 +43,7 @@ class WebsiteConfigSerializer(serializers.ModelSerializer):
class JudgeServerSerializer(serializers.ModelSerializer):
create_time = DateTimeTZField()
last_heartbeat = DateTimeTZField()
status = serializers.CharField()
class Meta:
model = JudgeServer