Merge "Using count() instead of all() for getting incompleted tasks"
This commit is contained in:
commit
94bfbeabfa
mistral
db/v2
engine
tests/unit/db/v2
@ -312,6 +312,10 @@ def get_incomplete_task_executions(**kwargs):
|
|||||||
return IMPL.get_incomplete_task_executions(**kwargs)
|
return IMPL.get_incomplete_task_executions(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def get_incomplete_task_executions_count(**kwargs):
|
||||||
|
return IMPL.get_incomplete_task_executions_count(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
def create_task_execution(values):
|
def create_task_execution(values):
|
||||||
return IMPL.create_task_execution(values)
|
return IMPL.create_task_execution(values)
|
||||||
|
|
||||||
|
@ -797,7 +797,7 @@ def get_task_executions(**kwargs):
|
|||||||
return _get_task_executions(**kwargs)
|
return _get_task_executions(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
def get_incomplete_task_executions(**kwargs):
|
def _get_incomplete_task_executions_query(kwargs):
|
||||||
query = b.model_query(models.TaskExecution)
|
query = b.model_query(models.TaskExecution)
|
||||||
|
|
||||||
query = query.filter_by(**kwargs)
|
query = query.filter_by(**kwargs)
|
||||||
@ -811,9 +811,21 @@ def get_incomplete_task_executions(**kwargs):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return query
|
||||||
|
|
||||||
|
|
||||||
|
def get_incomplete_task_executions(**kwargs):
|
||||||
|
query = _get_incomplete_task_executions_query(kwargs)
|
||||||
|
|
||||||
return query.all()
|
return query.all()
|
||||||
|
|
||||||
|
|
||||||
|
def get_incomplete_task_executions_count(**kwargs):
|
||||||
|
query = _get_incomplete_task_executions_query(kwargs)
|
||||||
|
|
||||||
|
return query.count()
|
||||||
|
|
||||||
|
|
||||||
@b.session_aware()
|
@b.session_aware()
|
||||||
def create_task_execution(values, session=None):
|
def create_task_execution(values, session=None):
|
||||||
task_ex = models.TaskExecution()
|
task_ex = models.TaskExecution()
|
||||||
|
@ -52,6 +52,7 @@ def on_action_complete(action_ex, result):
|
|||||||
task_handler.schedule_on_action_complete(action_ex)
|
task_handler.schedule_on_action_complete(action_ex)
|
||||||
|
|
||||||
|
|
||||||
|
@profiler.trace('action-handler-build-action')
|
||||||
def _build_action(action_ex):
|
def _build_action(action_ex):
|
||||||
if isinstance(action_ex, models.WorkflowExecution):
|
if isinstance(action_ex, models.WorkflowExecution):
|
||||||
return actions.WorkflowAction(None, action_ex=action_ex)
|
return actions.WorkflowAction(None, action_ex=action_ex)
|
||||||
|
@ -280,11 +280,11 @@ class Workflow(object):
|
|||||||
|
|
||||||
# Workflow is not completed if there are any incomplete task
|
# Workflow is not completed if there are any incomplete task
|
||||||
# executions.
|
# executions.
|
||||||
incomplete_tasks = db_api.get_incomplete_task_executions(
|
incomplete_tasks_count = db_api.get_incomplete_task_executions_count(
|
||||||
workflow_execution_id=self.wf_ex.id,
|
workflow_execution_id=self.wf_ex.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
if incomplete_tasks:
|
if incomplete_tasks_count > 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
wf_ctrl = wf_base.get_controller(self.wf_ex, self.wf_spec)
|
wf_ctrl = wf_base.get_controller(self.wf_ex, self.wf_spec)
|
||||||
|
@ -1401,6 +1401,51 @@ class TaskExecutionTest(SQLAlchemyTest):
|
|||||||
created.id
|
created.id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_get_incomplete_task_executions(self):
|
||||||
|
wf_ex = db_api.create_workflow_execution(WF_EXECS[0])
|
||||||
|
|
||||||
|
values = copy.deepcopy(TASK_EXECS[0])
|
||||||
|
values.update({'workflow_execution_id': wf_ex.id})
|
||||||
|
values['state'] = 'RUNNING'
|
||||||
|
|
||||||
|
task_ex1 = db_api.create_task_execution(values)
|
||||||
|
|
||||||
|
task_execs = db_api.get_incomplete_task_executions(
|
||||||
|
workflow_execution_id=wf_ex.id
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(1, len(task_execs))
|
||||||
|
self.assertEqual(task_ex1, task_execs[0])
|
||||||
|
self.assertEqual(
|
||||||
|
1,
|
||||||
|
db_api.get_incomplete_task_executions_count(
|
||||||
|
workflow_execution_id=wf_ex.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add one more task.
|
||||||
|
|
||||||
|
values = copy.deepcopy(TASK_EXECS[1])
|
||||||
|
values.update({'workflow_execution_id': wf_ex.id})
|
||||||
|
values['state'] = 'SUCCESS'
|
||||||
|
|
||||||
|
db_api.create_task_execution(values)
|
||||||
|
|
||||||
|
# It should be still one incompleted task.
|
||||||
|
|
||||||
|
task_execs = db_api.get_incomplete_task_executions(
|
||||||
|
workflow_execution_id=wf_ex.id
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(1, len(task_execs))
|
||||||
|
self.assertEqual(task_ex1, task_execs[0])
|
||||||
|
self.assertEqual(
|
||||||
|
1,
|
||||||
|
db_api.get_incomplete_task_executions_count(
|
||||||
|
workflow_execution_id=wf_ex.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def test_task_execution_repr(self):
|
def test_task_execution_repr(self):
|
||||||
wf_ex = db_api.create_workflow_execution(WF_EXECS[0])
|
wf_ex = db_api.create_workflow_execution(WF_EXECS[0])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user