Commit bc1550c0 by Carpoon

Add periodic cleanup task for datastore exports

parent 2c1ce944
......@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
import unittest
from unittest import TestCase
from unittest.mock import patch, MagicMock
from django.contrib.auth.models import User
......@@ -26,7 +26,7 @@ from ..tasks import local_periodic_tasks
@patch.object(local_periodic_tasks, 'send_mail')
@patch.object(Notification, 'objects')
class EmailNotificationTestCase(unittest.TestCase):
class EmailNotificationTestCase(TestCase):
nextpk = 0
......
......@@ -64,6 +64,11 @@ celery.conf.update(
'schedule': timedelta(hours=1),
'options': {'queue': 'localhost.man'}
},
'storage.periodic_export_tasks': {
'task': 'storage.tasks.periodic_tasks.export_garbage_disk_collector',
'schedule': timedelta(minutes=1),
'options': {'queue': 'localhost.man.slow'}
},
'dashboard.send_email_notifications': {
'task': 'dashboard.tasks.local_periodic_tasks.'
'send_email_notifications',
......
......@@ -14,8 +14,12 @@
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from datetime import timedelta
from storage.models import DataStore
from django.conf import settings
from django.utils.timezone import now
from storage.models import DataStore, ExportedDisk
from vm.models import ExportedVM
from manager.mancelery import celery
import logging
from storage.tasks import storage_tasks
......@@ -52,6 +56,26 @@ def garbage_collector(timeout=15):
@celery.task
def export_garbage_disk_collector(timeout=60):
""" Garbage collector for exported disk images.
:param timeout: Seconds before TimeOut exception
:type timeout: int
"""
logger.info("export_garbage_disk_collector periodic task started...")
for exported_disk in ExportedDisk.objects.all():
if exported_disk.created + timedelta(hours=settings.EXPORT_KEEP_TIME_IN_HOURS) < now():
logger.info("Removed exported disk: %s" % exported_disk.filename)
exported_disk.delete()
for exported_vm in ExportedVM.objects.all():
if exported_vm.created + timedelta(hours=settings.EXPORT_KEEP_TIME_IN_HOURS) < now():
logger.info("Removed exported VM: %s" % exported_vm.filename)
exported_vm.delete()
@celery.task
def list_orphan_disks(timeout=15):
"""List disk image files without Disk object in the database.
......
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