Commit a6e93b0b by Bach Dániel

vm: fix garbage collector

parent c369ff1e
......@@ -616,21 +616,23 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
interval what the Lease allows. This rate is configurable with the
only parameter, threshold (0.1 = 10% by default).
"""
return (self._is_suspend_expiring(self, threshold) or
self._is_delete_expiring(self, threshold))
return (self._is_suspend_expiring(threshold) or
self._is_delete_expiring(threshold))
def _is_suspend_expiring(self, threshold=0.1):
interval = self.lease.suspend_interval
if interval is not None:
limit = timezone.now() + threshold * self.lease.suspend_interval
if self.time_of_suspend is not None and interval is not None:
limit = timezone.now() + timedelta(seconds=(
threshold * self.lease.suspend_interval.total_seconds()))
return limit > self.time_of_suspend
else:
return False
def _is_delete_expiring(self, threshold=0.1):
interval = self.lease.delete_interval
if interval is not None:
limit = timezone.now() + threshold * self.lease.delete_interval
if self.time_of_delete is not None and interval is not None:
limit = timezone.now() + timedelta(seconds=(
threshold * self.lease.delete_interval.total_seconds()))
return limit > self.time_of_delete
else:
return False
......
......@@ -26,7 +26,7 @@ def garbage_collector(timeout=15):
"""
now = timezone.now()
for i in Instance.objects.filter(destroyed=None).all():
if i.time_of_delete and now < i.time_of_delete:
if i.time_of_delete and now > i.time_of_delete:
i.destroy_async()
logger.info("Expired instance %d destroyed.", i.pk)
try:
......@@ -37,7 +37,7 @@ def garbage_collector(timeout=15):
except Exception as e:
logger.debug('Could not notify owner of instance %d .%s',
i.pk, unicode(e))
elif (i.time_of_suspend and now < i.time_of_suspend and
elif (i.time_of_suspend and now > i.time_of_suspend and
i.state == 'RUNNING'):
i.sleep_async()
logger.info("Expired instance %d suspended." % i.pk)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment