Simplify error and warning code
This commit is contained in:
parent
4c3bafdcca
commit
8a6984ef48
|
@ -11,25 +11,15 @@ class Repo(models.Model):
|
||||||
last_modified = models.DateTimeField()
|
last_modified = models.DateTimeField()
|
||||||
label = models.OneToOneField(Label, on_delete=models.CASCADE, unique=True)
|
label = models.OneToOneField(Label, on_delete=models.CASCADE, unique=True)
|
||||||
|
|
||||||
def warning(self):
|
def warning(self, hours_ago=2):
|
||||||
if self.error():
|
return not self.latest_archive().start > datetime.utcnow() - timedelta(hours=hours_ago)
|
||||||
return True
|
|
||||||
else:
|
|
||||||
latest_archive = self.latest_archive()
|
|
||||||
if latest_archive.start > datetime.utcnow() - timedelta(hours=2):
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
def error(self):
|
def error(self, hours_ago=4):
|
||||||
latest_archive = self.latest_archive()
|
latest_archive = self.latest_archive()
|
||||||
if latest_archive is None or not self.archive_after_latest_error():
|
if latest_archive is None or not self.archive_after_latest_error():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if latest_archive.start > datetime.utcnow() - timedelta(hours=4):
|
return not latest_archive.start > datetime.utcnow() - timedelta(hours=hours_ago)
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
def archive_after_latest_error(self):
|
def archive_after_latest_error(self):
|
||||||
latest_archive = self.latest_archive()
|
latest_archive = self.latest_archive()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user