Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
5
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
bc1550c0
authored
Dec 14, 2023
by
Carpoon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add periodic cleanup task for datastore exports
parent
2c1ce944
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
3 deletions
+32
-3
circle/dashboard/tests/test_periodic_task.py
+2
-2
circle/manager/mancelery.py
+5
-0
circle/storage/tasks/periodic_tasks.py
+25
-1
No files found.
circle/dashboard/tests/test_periodic_task.py
View file @
bc1550c0
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
import
unittest
from
unittest
import
TestCase
from
unittest.mock
import
patch
,
MagicMock
from
unittest.mock
import
patch
,
MagicMock
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
...
@@ -26,7 +26,7 @@ from ..tasks import local_periodic_tasks
...
@@ -26,7 +26,7 @@ from ..tasks import local_periodic_tasks
@patch.object
(
local_periodic_tasks
,
'send_mail'
)
@patch.object
(
local_periodic_tasks
,
'send_mail'
)
@patch.object
(
Notification
,
'objects'
)
@patch.object
(
Notification
,
'objects'
)
class
EmailNotificationTestCase
(
unittest
.
TestCase
):
class
EmailNotificationTestCase
(
TestCase
):
nextpk
=
0
nextpk
=
0
...
...
circle/manager/mancelery.py
View file @
bc1550c0
...
@@ -64,6 +64,11 @@ celery.conf.update(
...
@@ -64,6 +64,11 @@ celery.conf.update(
'schedule'
:
timedelta
(
hours
=
1
),
'schedule'
:
timedelta
(
hours
=
1
),
'options'
:
{
'queue'
:
'localhost.man'
}
'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'
:
{
'dashboard.send_email_notifications'
:
{
'task'
:
'dashboard.tasks.local_periodic_tasks.'
'task'
:
'dashboard.tasks.local_periodic_tasks.'
'send_email_notifications'
,
'send_email_notifications'
,
...
...
circle/storage/tasks/periodic_tasks.py
View file @
bc1550c0
...
@@ -14,8 +14,12 @@
...
@@ -14,8 +14,12 @@
#
#
# You should have received a copy of the GNU General Public License along
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
# 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
from
manager.mancelery
import
celery
import
logging
import
logging
from
storage.tasks
import
storage_tasks
from
storage.tasks
import
storage_tasks
...
@@ -52,6 +56,26 @@ def garbage_collector(timeout=15):
...
@@ -52,6 +56,26 @@ def garbage_collector(timeout=15):
@celery.task
@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
):
def
list_orphan_disks
(
timeout
=
15
):
"""List disk image files without Disk object in the database.
"""List disk image files without Disk object in the database.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment