Use update_task_metadata in set_task_progress

Instead of duplicating logic done for updating
or creating a task details metadata property we
can just use the new update_task_metadata as
the single function that can do this.

Change-Id: I66041a157b3f37ca083f8e743ec348ca8feacac6
This commit is contained in:
Joshua Harlow
2013-12-06 18:19:55 -08:00
parent b9a047f27d
commit 40f1a798d1

View File

@@ -152,9 +152,9 @@ class Storage(object):
def update_task_metadata(self, uuid, update_with): def update_task_metadata(self, uuid, update_with):
if not update_with: if not update_with:
return return
# NOTE(harlowja): this is a read and then write, not in 1 transcation # NOTE(harlowja): this is a read and then write, not in 1 transaction
# so it is entirely possible that we could write over another writes # so it is entirely possible that we could write over another writes
# metadata update. # metadata update. Maybe add some merging logic later?
td = self._taskdetail_by_uuid(uuid) td = self._taskdetail_by_uuid(uuid)
if not td.meta: if not td.meta:
td.meta = {} td.meta = {}
@@ -168,20 +168,21 @@ class Storage(object):
:param progress: task progress :param progress: task progress
:param details: task specific progress information :param details: task specific progress information
""" """
td = self._taskdetail_by_uuid(uuid) metadata_update = {
if not td.meta: 'progress': progress,
td.meta = {} }
td.meta['progress'] = progress
if details is not None: if details is not None:
# NOTE(imelnikov): as we can update progress without # NOTE(imelnikov): as we can update progress without
# updating details (e.g. automatically from engine) # updating details (e.g. automatically from engine)
# we save progress value with details, too # we save progress value with details, too
if details: if details:
td.meta['progress_details'] = dict(at_progress=progress, metadata_update['progress_details'] = {
details=details) 'at_progress': progress,
'details': details,
}
else: else:
td.meta['progress_details'] = None metadata_update['progress_details'] = None
self._with_connection(self._save_task_detail, task_detail=td) self.update_task_metadata(uuid, metadata_update)
def get_task_progress(self, uuid): def get_task_progress(self, uuid):
"""Get progress of task with given uuid. """Get progress of task with given uuid.