From 56d0b35898acd9c9ba6c8f790a0e3d467f4d1f22 Mon Sep 17 00:00:00 2001 From: Renat Akhmerov Date: Sun, 14 Aug 2016 13:49:18 +0700 Subject: [PATCH] Optimize task defer() method * Replace expensive search for a task execution in Task.defer() which caused the whole wf_ex.task_executions collection with a DB query to find a single object Change-Id: I45d621fdf88ca31efb3cc8f3c6f879d82ce820b1 --- mistral/engine/tasks.py | 11 ++++------- mistral/tests/unit/engine/base.py | 7 ++++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/mistral/engine/tasks.py b/mistral/engine/tasks.py index c485dcdf..caac96c5 100644 --- a/mistral/engine/tasks.py +++ b/mistral/engine/tasks.py @@ -31,7 +31,6 @@ from mistral.utils import wf_trace from mistral.workflow import base as wf_base from mistral.workflow import data_flow from mistral.workflow import states -from mistral.workflow import utils as wf_utils from mistral.workflow import with_items @@ -81,14 +80,12 @@ class Task(object): def defer(self): """Defers task. - This methods finds task execution or creates new and puts task - to a waiting state. + This method puts task to a waiting state. """ - if not self.task_ex: - t_execs = wf_utils.find_task_executions_by_spec( - self.wf_ex, - self.task_spec + t_execs = db_api.get_task_executions( + workflow_execution_id=self.wf_ex.id, + name=self.task_spec.get_name() ) self.task_ex = t_execs[0] if t_execs else None diff --git a/mistral/tests/unit/engine/base.py b/mistral/tests/unit/engine/base.py index 29ecf485..3d131aa2 100644 --- a/mistral/tests/unit/engine/base.py +++ b/mistral/tests/unit/engine/base.py @@ -129,9 +129,10 @@ class EngineTestCase(base.DbTestCase): [thread.kill() for thread in self.threads] @staticmethod - def print_executions(exc_info): - print("\nEngine test case exception occurred: %s" % exc_info[1]) - print("Exception type: %s" % exc_info[0]) + def print_executions(exc_info=None): + if exc_info: + print("\nEngine test case exception occurred: %s" % exc_info[1]) + print("Exception type: %s" % exc_info[0]) print("\nPrinting workflow executions...")