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
This commit is contained in:
Renat Akhmerov 2016-08-14 13:49:18 +07:00
parent c459aeeeee
commit 56d0b35898
2 changed files with 8 additions and 10 deletions

View File

@ -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

View File

@ -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...")