Send in the prior atom state on notification of a state change
When a retry atom or a task atom changes state it is quite useful to know the prior state the atom was in; to make this easier pass that information along in the details about the state transition so that observers can inspect it if they desire to. This matches more closely with the flow notification which does include the prior state (under the details key 'old_state') so this also increases the uniformity of notifications in general. Change-Id: I7df1fcc60ba178198776ddaa2681caee5811c4ff
This commit is contained in:
@@ -51,21 +51,24 @@ class RetryAction(object):
|
||||
return kwargs
|
||||
|
||||
def change_state(self, retry, state, result=None):
|
||||
old_state = self._storage.get_atom_state(retry.name)
|
||||
if state in SAVE_RESULT_STATES:
|
||||
self._storage.save(retry.name, result, state)
|
||||
elif state == states.REVERTED:
|
||||
self._storage.cleanup_retry_history(retry.name, state)
|
||||
else:
|
||||
old_state = self._storage.get_atom_state(retry.name)
|
||||
if state == old_state:
|
||||
# NOTE(imelnikov): nothing really changed, so we should not
|
||||
# write anything to storage and run notifications
|
||||
return
|
||||
self._storage.set_atom_state(retry.name, state)
|
||||
retry_uuid = self._storage.get_atom_uuid(retry.name)
|
||||
details = dict(retry_name=retry.name,
|
||||
retry_uuid=retry_uuid,
|
||||
result=result)
|
||||
details = {
|
||||
'retry_name': retry.name,
|
||||
'retry_uuid': retry_uuid,
|
||||
'result': result,
|
||||
'old_state': old_state,
|
||||
}
|
||||
self._notifier.notify(state, details)
|
||||
|
||||
def execute(self, retry):
|
||||
|
||||
@@ -39,11 +39,10 @@ class TaskAction(object):
|
||||
def handles(atom):
|
||||
return isinstance(atom, task_atom.BaseTask)
|
||||
|
||||
def _is_identity_transition(self, state, task, progress):
|
||||
def _is_identity_transition(self, old_state, state, task, progress):
|
||||
if state in SAVE_RESULT_STATES:
|
||||
# saving result is never identity transition
|
||||
return False
|
||||
old_state = self._storage.get_atom_state(task.name)
|
||||
if state != old_state:
|
||||
# changing state is not identity transition by definition
|
||||
return False
|
||||
@@ -58,7 +57,8 @@ class TaskAction(object):
|
||||
return True
|
||||
|
||||
def change_state(self, task, state, result=None, progress=None):
|
||||
if self._is_identity_transition(state, task, progress):
|
||||
old_state = self._storage.get_atom_state(task.name)
|
||||
if self._is_identity_transition(old_state, state, task, progress):
|
||||
# NOTE(imelnikov): ignore identity transitions in order
|
||||
# to avoid extra write to storage backend and, what's
|
||||
# more important, extra notifications
|
||||
@@ -70,9 +70,12 @@ class TaskAction(object):
|
||||
if progress is not None:
|
||||
self._storage.set_task_progress(task.name, progress)
|
||||
task_uuid = self._storage.get_atom_uuid(task.name)
|
||||
details = dict(task_name=task.name,
|
||||
task_uuid=task_uuid,
|
||||
result=result)
|
||||
details = {
|
||||
'task_name': task.name,
|
||||
'task_uuid': task_uuid,
|
||||
'result': result,
|
||||
'old_state': old_state,
|
||||
}
|
||||
self._notifier.notify(state, details)
|
||||
if progress is not None:
|
||||
task.update_progress(progress)
|
||||
|
||||
Reference in New Issue
Block a user