WIP: New fields added to action execution context

* with_items_index describes the current index of action,
if there is no with-items tasks it should be 0.
* task_rerun_no describes the current rerun index,
if it is first run it should be 0.
* task_rerun_id specifies id task has within
each rerun. This id should be refreshed after each rerun.

All these fields will be helpful for writing custom actions

Depends-On: https://review.opendev.org/c/openstack/mistral-lib/+/897638
Signed-off-by: Oleg Ovcharuk <vgvoleg@gmail.com>
Change-Id: Iabc1d6f8f5e3339a5b5a07e8a10c32ede3f657e8
Signed-off-by: Oleg Ovcharuk <vgvoleg@gmail.com>
This commit is contained in:
Oleg Ovcharuk 2023-10-08 20:29:39 +03:00
parent 4446f9ced8
commit 415a47d30a
2 changed files with 20 additions and 3 deletions

View File

@ -138,7 +138,7 @@ class Action(object, metaclass=abc.ABCMeta):
"""
raise NotImplementedError
def _prepare_execution_context(self):
def _prepare_execution_context(self, with_items_index=0):
res = {}
if self.task_ex:
@ -147,6 +147,13 @@ class Action(object, metaclass=abc.ABCMeta):
res['workflow_execution_id'] = wf_ex.id
res['task_execution_id'] = self.task_ex.id
res['workflow_name'] = wf_ex.name
res['with_items_index'] = with_items_index
res['task_rerun_no'] = self.task_ex.runtime_context.get(
'task_rerun_no'
)
res['task_rerun_id'] = self.task_ex.runtime_context.get(
'task_rerun_id'
)
if self.action_ex:
res['action_execution_id'] = self.action_ex.id
@ -287,7 +294,7 @@ class RegularAction(Action):
action,
self.action_ex.id if self.action_ex is not None else None,
safe_rerun,
self._prepare_execution_context(),
self._prepare_execution_context(with_items_index=index),
target=target,
timeout=timeout
)
@ -333,7 +340,7 @@ class RegularAction(Action):
action,
self.action_ex.id if self.action_ex is not None else None,
safe_rerun,
self._prepare_execution_context(),
self._prepare_execution_context(with_items_index=index),
target=target,
async_=False,
timeout=timeout

View File

@ -603,6 +603,14 @@ class RegularTask(Task):
else:
self._run_existing()
def _generate_task_rerun_data(self):
self.task_ex.runtime_context["task_rerun_id"] = \
utils.generate_unicode_uuid()
if "task_rerun_no" not in self.task_ex.runtime_context:
self.task_ex.runtime_context["task_rerun_no"] = 0
else:
self.task_ex.runtime_context["task_rerun_no"] += 1
@profiler.trace('task-run-new')
def _run_new(self):
if self.waiting:
@ -623,6 +631,7 @@ class RegularTask(Task):
self.wf_ex.id
)
self._generate_task_rerun_data()
self._before_task_start()
# Policies could possibly change task state.
@ -654,6 +663,7 @@ class RegularTask(Task):
self.set_state(states.RUNNING, None, processed=False)
if self.rerun:
self._generate_task_rerun_id()
self._before_task_start()
# Policies could possibly change task state.