Commit ba6e96a6 by Szeberényi Imre

grace period for deleting VMs

parent a58577ec
Pipeline #1083 passed with stage
in 0 seconds
......@@ -42,8 +42,11 @@ def garbage_collector(timeout=15):
:type timeout: int
"""
now = timezone.now()
grace_period = timezone.timedelta(hours=1)
work_package = 20
for i in Instance.objects.filter(destroyed_at=None).all():
if i.time_of_delete and now > i.time_of_delete:
if i.time_of_delete and now > i.time_of_delete + grace_period and work_package > 0:
work_package -= 1
i.destroy.async(system=True)
logger.info("Expired instance %d destroyed.", i.pk)
try:
......@@ -57,7 +60,8 @@ def garbage_collector(timeout=15):
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
i.state == 'RUNNING'):
i.state == 'RUNNING') and work_package > 0:
work_package -= 1
logger.info("Expired instance %d suspended." % i.pk)
try:
i.sleep.async(system=True)
......
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