set capacity to 0 if instance has not checked in lately

This commit is contained in:
AlanCoding
2017-07-25 15:35:44 -04:00
parent 53700c10b9
commit 1112557c79
4 changed files with 60 additions and 18 deletions

View File

@@ -5,6 +5,8 @@ from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.utils.timezone import now, timedelta
from solo.models import SingletonModel
@@ -53,6 +55,14 @@ class Instance(models.Model):
# NOTE: TODO: Likely to repurpose this once standalone ramparts are a thing
return "awx"
def is_lost(self, ref_time=None, isolated=False):
if ref_time is None:
ref_time = now()
grace_period = 120
if isolated:
grace_period = settings.AWX_ISOLATED_PERIODIC_CHECK * 2
return self.modified < ref_time - timedelta(seconds=grace_period)
class InstanceGroup(models.Model):
"""A model representing a Queue/Group of AWX Instances."""