Add a soft delete functionality for tasks.

Currently there is no mechanism for deleting tasks on regular basis.
This patch adds a new function that is called in the tasks_get_all
function, so that everytime tasks lists are called, the function
checks if tasks in the database have surpassed the expired_at value.
If that is the case, then it sets the deleted value as 1 for all the
expired tasks.

Co-Authored-By: Mike Fedosin <mfedosin@mirantis.com>

Implements https://review.openstack.org/#/c/324648/
Change-Id: I0bde982de948901f6bfbfab9e57cf84891c22052
This commit is contained in:
GeetikaBatra
2015-08-05 02:16:10 +05:30
parent 13a17a814e
commit 38563b0555
6 changed files with 106 additions and 8 deletions

View File

@@ -959,6 +959,20 @@ def task_delete(context, task_id):
raise exception.TaskNotFound(task_id=task_id)
def _task_soft_delete(context):
"""Scrub task entities which are expired """
global DATA
now = timeutils.utcnow()
tasks = DATA['tasks'].values()
for task in tasks:
if(task['owner'] == context.owner and task['deleted'] == False
and task['expires_at'] <= now):
task['deleted'] = True
task['deleted_at'] = timeutils.utcnow()
@log_call
def task_get_all(context, filters=None, marker=None, limit=None,
sort_key='created_at', sort_dir='desc'):
@@ -972,6 +986,7 @@ def task_get_all(context, filters=None, marker=None, limit=None,
:param sort_dir: direction in which results should be sorted (asc, desc)
:returns: tasks set
"""
_task_soft_delete(context)
filters = filters or {}
tasks = DATA['tasks'].values()
tasks = _filter_tasks(tasks, filters, context)