Fix calculating task execution result for "with-items"

* The logic of calculating a task result in case of "with-items" was
  overcomplicated and broke encapsulation of a "with-items" task.
  This patch makes it simpler, so that the method doesn't need to
  peek into the internals of a "with-items" task (e.g. runtime_context).

Change-Id: I036193cbae15d7f3c3414b123525ceafa91fdeb1
This commit is contained in:
Renat Akhmerov 2020-06-02 15:48:00 +07:00
parent ddf9577785
commit 7dec19ae19
2 changed files with 7 additions and 10 deletions

View File

@ -377,6 +377,10 @@ class RetryPolicy(base.TaskPolicy):
# retried as-is, because these tasks can't start without
# a correct logical state.
if hasattr(task.task_spec, "get_join") and task.task_spec.get_join():
# TODO(rakhmerov): This is an example of broken encapsulation.
# The control over such operations should belong to the class Task.
# If it's done, from the outside of the class there will be just
# one visible operation "continue_task()" or something like that.
from mistral.engine import task_handler as t_h
task.set_state(

View File

@ -167,16 +167,9 @@ def get_task_execution_result(task_ex):
if hasattr(ex, 'output') and ex.accepted
]
task_spec = spec_parser.get_task_spec(task_ex.spec)
if task_spec.get_with_items():
# TODO(rakhmerov): Smell: violation of 'with-items' encapsulation.
with_items_ctx = task_ex.runtime_context.get('with_items')
if with_items_ctx and with_items_ctx.get('count') > 0:
return results
else:
return []
# If it's a 'with-items' task we should always return an array.
if spec_parser.get_task_spec(task_ex.spec).get_with_items():
return results
return results[0] if len(results) == 1 else results