Skip to content

Commit

Permalink
Merge "Do not erase task progress details"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Oct 22, 2013
2 parents 004d483 + 176bfa6 commit 2532be0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
2 changes: 1 addition & 1 deletion taskflow/engines/action_engine/task_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _on_update_progress(self, task, event_data, progress, **kwargs):
"""Update task progress value that stored in engine."""
try:
engine = event_data['engine']
engine.storage.set_task_progress(self.uuid, progress, **kwargs)
engine.storage.set_task_progress(self.uuid, progress, kwargs)
except Exception:
# Update progress callbacks should never fail, so capture and log
# the emitted exception instead of raising it.
Expand Down
18 changes: 11 additions & 7 deletions taskflow/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,26 @@ def get_task_state(self, uuid):
"""Get state of task with given uuid"""
return self._taskdetail_by_uuid(uuid).state

def set_task_progress(self, uuid, progress, **kwargs):
def set_task_progress(self, uuid, progress, details=None):
"""Set task progress.
:param uuid: task uuid
:param progress: task progress
:param kwargs: task specific progress information
:param details: task specific progress information
"""
td = self._taskdetail_by_uuid(uuid)
if not td.meta:
td.meta = {}
td.meta['progress'] = progress
if kwargs:
td.meta['progress_details'] = kwargs
else:
if 'progress_details' in td.meta:
td.meta.pop('progress_details')
if details is not None:
# NOTE(imelnikov): as we can update progress without
# updating details (e.g. automatically from engine)
# we save progress value with details, too
if details:
td.meta['progress_details'] = dict(at_progress=progress,
details=details)
else:
td.meta['progress_details'] = None
self._with_connection(self._save_task_detail, task_detail=td)

def get_task_progress(self, uuid):
Expand Down
25 changes: 23 additions & 2 deletions taskflow/tests/unit/test_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def execute(self):
self.update_progress(progress)


class ProgressTaskWithDetails(task.Task):
def execute(self):
self.update_progress(0.5, test='test data', foo='bar')


class TestProgress(test.TestCase):
def _make_engine(self, flow, flow_detail=None, backend=None):
e = taskflow.engines.load(flow,
Expand Down Expand Up @@ -99,7 +104,22 @@ def test_storage_progress(self):
end_progress = e.storage.get_task_progress(t_uuid)
self.assertEquals(1.0, end_progress)
td = fd.find(t_uuid)
self.assertEquals({'progress': 1.0}, td.meta)
self.assertEquals(1.0, td.meta['progress'])
self.assertFalse(td.meta['progress_details'])

def test_storage_progress_detail(self):
flo = ProgressTaskWithDetails("test")
e = self._make_engine(flo)
e.run()
t_uuid = e.storage.get_uuid_by_name("test")
end_progress = e.storage.get_task_progress(t_uuid)
self.assertEquals(1.0, end_progress)
end_details = e.storage.get_task_progress_details(t_uuid)
self.assertEquals(end_details.get('at_progress'), 0.5)
self.assertEquals(end_details.get('details'), {
'test': 'test data',
'foo': 'bar'
})

def test_dual_storage_progress(self):
fired_events = []
Expand All @@ -120,5 +140,6 @@ def notify_me(task, event_data, progress):
end_progress = e.storage.get_task_progress(t_uuid)
self.assertEquals(1.0, end_progress)
td = fd.find(t_uuid)
self.assertEquals({'progress': 1.0}, td.meta)
self.assertEquals(1.0, td.meta['progress'])
self.assertFalse(td.meta['progress_details'])
self.assertEquals(6, len(fired_events))
23 changes: 20 additions & 3 deletions taskflow/tests/unit/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,27 @@ def test_default_task_progress(self):
def test_task_progress(self):
s = self._get_storage()
s.add_task('42', 'my task')
s.set_task_progress('42', 0.5, test_data=11)

s.set_task_progress('42', 0.5, {'test_data': 11})
self.assertEquals(s.get_task_progress('42'), 0.5)
self.assertEquals(s.get_task_progress_details('42'),
{'test_data': 11})
self.assertEquals(s.get_task_progress_details('42'), {
'at_progress': 0.5,
'details': {'test_data': 11}
})

s.set_task_progress('42', 0.7, {'test_data': 17})
self.assertEquals(s.get_task_progress('42'), 0.7)
self.assertEquals(s.get_task_progress_details('42'), {
'at_progress': 0.7,
'details': {'test_data': 17}
})

s.set_task_progress('42', 0.99)
self.assertEquals(s.get_task_progress('42'), 0.99)
self.assertEquals(s.get_task_progress_details('42'), {
'at_progress': 0.7,
'details': {'test_data': 17}
})

def test_fetch_result_not_ready(self):
s = self._get_storage()
Expand Down

0 comments on commit 2532be0

Please sign in to comment.