Moving task type constants into Mistral task specifications module

* There were references to Mistral specific constants mistakenly
  placed into mistral-lib. This patch adds these constants into
  the module where task language specifications are declared and
  changes the corresponding references.

Change-Id: I8c7c6896f01894ac76cf9365abfdce17e7df7662
This commit is contained in:
Renat Akhmerov 2020-06-04 18:19:52 +07:00
parent 8953999bc5
commit 2ad7bb829b
4 changed files with 21 additions and 13 deletions

View File

@ -23,7 +23,7 @@ import yaml
from mistral.db import utils as db_utils
from mistral.db.v2 import api as db_api
from mistral.utils import filter_utils
from mistral_lib import utils
from mistral_lib import utils as ml_utils
# Additional YAQL/Jinja functions provided by Mistral out of the box.
# If a function name ends with underscore then it doesn't need to pass
@ -160,8 +160,11 @@ def _should_pass_filter(t, state, flat):
if state:
state_match = t['state'] == state
# To break cyclic dependency.
from mistral.lang.v2 import tasks as lang_tasks
if flat:
is_action = t['type'] == utils.ACTION_TASK_TYPE
is_action = t['type'] == lang_tasks.ACTION_TASK_TYPE
if not is_action:
nested_execs = db_api.get_workflow_executions(
@ -194,12 +197,15 @@ def _get_tasks_from_db(workflow_execution_id=None, recursive=False, state=None,
task_execs.extend(db_api.get_task_executions(**kwargs))
# To break cyclic dependency.
from mistral.lang.v2 import tasks as lang_tasks
# If it is not recursive no need to check nested workflows.
# If there is no workflow execution id, we already have all we need, and
# doing more queries will just create duplication in the results.
if recursive and workflow_execution_id:
for t in task_execs:
if t.type == utils.WORKFLOW_TASK_TYPE:
if t.type == lang_tasks.WORKFLOW_TASK_TYPE:
# Get nested workflow execution that matches the task.
nested_workflow_executions = db_api.get_workflow_executions(
task_execution_id=t.id
@ -265,7 +271,7 @@ def _convert_to_user_model(task_ex):
def uuid_(context=None):
return utils.generate_unicode_uuid()
return ml_utils.generate_unicode_uuid()
def global_(context, var_name):

View File

@ -30,7 +30,13 @@ from mistral.lang.v2 import retry_policy
from mistral.workflow import states
from mistral_lib import utils
# Task types.
ACTION_TASK_TYPE = 'ACTION'
WORKFLOW_TASK_TYPE = 'WORKFLOW'
_expr_ptrns = [expressions.patterns[name] for name in expressions.patterns]
WITH_ITEMS_PTRN = re.compile(
r"\s*([\w\d_\-]+)\s*in\s*(\[.+\]|%s)" % '|'.join(_expr_ptrns)
)
@ -264,8 +270,8 @@ class TaskSpec(base.BaseSpec):
return self._safe_rerun
def get_type(self):
return (utils.WORKFLOW_TASK_TYPE if self._workflow
else utils.ACTION_TASK_TYPE)
return (WORKFLOW_TASK_TYPE if self._workflow
else ACTION_TASK_TYPE)
class DirectWorkflowTaskSpec(TaskSpec):
@ -311,6 +317,7 @@ class DirectWorkflowTaskSpec(TaskSpec):
if self._join:
join_task_name = self.get_name()
if len(join_task_name) > MAX_LENGTH_JOIN_TASK_NAME:
raise exc.InvalidModelException(
"The length of a '{0}' join task name must not exceed {1} "
@ -343,6 +350,7 @@ class DirectWorkflowTaskSpec(TaskSpec):
if on_clause and on_clause.get_publish():
if spec:
on_clause.get_publish().merge(spec)
return on_clause.get_publish()
return spec

View File

@ -15,7 +15,7 @@
import datetime
from unittest import mock
from mistral.db.v2.sqlalchemy import api as db_api
from mistral.db.v2 import api as db_api
from mistral import exceptions as exc
from mistral.expressions import jinja_expression as expr
from mistral.tests.unit import base

View File

@ -33,12 +33,6 @@ from mistral import expressions as expr
# Thread local storage.
_th_loc_storage = threading.local()
# TODO(rakhmerov): these two constants are misplaced. Utility methods
# should not be Mistral specific. They should be generic enough so to
# be moved to any other project w/o changes.
ACTION_TASK_TYPE = 'ACTION'
WORKFLOW_TASK_TYPE = 'WORKFLOW'
@contextlib.contextmanager
def tempdir(**kwargs):