Commit 479d230f by Szeberényi Imre

Garbage collector fix

parent 616472ae
Pipeline #1394 passed with stage
in 0 seconds
...@@ -44,10 +44,13 @@ def garbage_collector(offset=timezone.timedelta(seconds=20)): ...@@ -44,10 +44,13 @@ def garbage_collector(offset=timezone.timedelta(seconds=20)):
:type timeout: int :type timeout: int
""" """
now = timezone.now() now = timezone.now()
grace_period = timezone.timedelta(hours=1) grace_period = timezone.timedelta(hours=0)
work_package = 20 work_package = 20
logger.debug("Garbage_collector START")
for i in Instance.objects.filter(destroyed_at=None).all(): for i in Instance.objects.filter(destroyed_at=None).all():
logger.debug("Garbage_collector work_package:%d %s: %s:", work_package, i.pk, now > i.time_of_delete)
if i.time_of_delete and now > i.time_of_delete + grace_period and work_package > 0: if i.time_of_delete and now > i.time_of_delete + grace_period and work_package > 0:
logger.debug("Garbage_collector delete")
work_package -= 1 work_package -= 1
i.destroy.async(system=True) i.destroy.async(system=True)
logger.info("Expired instance %d destroyed.", i.pk) logger.info("Expired instance %d destroyed.", i.pk)
...@@ -61,9 +64,9 @@ def garbage_collector(offset=timezone.timedelta(seconds=20)): ...@@ -61,9 +64,9 @@ def garbage_collector(offset=timezone.timedelta(seconds=20)):
except Exception as e: except Exception as e:
logger.debug('Could not notify owner of instance %d .%s', logger.debug('Could not notify owner of instance %d .%s',
i.pk, unicode(e)) 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' and work_package > 0:
i.state == 'RUNNING') and work_package > 0:
work_package -= 1 work_package -= 1
logger.debug("Garbage_collector suspend")
logger.info("Expired instance %d suspended." % i.pk) logger.info("Expired instance %d suspended." % i.pk)
try: try:
i.sleep.async(system=True) i.sleep.async(system=True)
...@@ -83,8 +86,8 @@ def garbage_collector(offset=timezone.timedelta(seconds=20)): ...@@ -83,8 +86,8 @@ def garbage_collector(offset=timezone.timedelta(seconds=20)):
logger.debug("Instance %d expires soon." % i.pk) logger.debug("Instance %d expires soon." % i.pk)
i.notify_owners_about_expiration() i.notify_owners_about_expiration()
else: else:
logger.debug("Instance %d didn't expire. bw:%d", i.pk, bw) logger.debug("Instance %d didn't expire. work_package:%d", i.pk, work_package)
logger.debug("Garbage_collector END work_package:%d", work_package)
@celery.task(ignore_result=True) @celery.task(ignore_result=True)
def auto_migrate(): def auto_migrate():
......
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