Example #1
0
def task(context, task_id=None, route=None):
    instances = None

    try:
        current_task = workflow_functions._get_current_task(context)
    except:
        current_task = {}

    if task_id is None:
        task_id = current_task['id']

    if route is None:
        route = current_task.get('route', 0)

    try:
        workflow_state = context['__state'] or {}
    except KeyError:
        workflow_state = {}

    task_state_pointers = workflow_state.get('tasks') or {}
    task_state_entry_uid = constants.TASK_STATE_ROUTE_FORMAT % (task_id,
                                                                str(route))
    task_state_entry_idx = task_state_pointers.get(task_state_entry_uid)

    # If unable to identify the task flow entry and if there are other routes, then
    # use an earlier route before the split to find the specific task.
    if task_state_entry_idx is None:
        if route > 0:
            current_route_details = workflow_state['routes'][route]
            # Reverse the list because we want to start with the next longest route.
            for idx, prev_route_details in enumerate(
                    reversed(workflow_state['routes'][:route])):
                if len(set(prev_route_details) -
                       set(current_route_details)) == 0:
                    # The index is from a reversed list so need to calculate
                    # the index of the item in the list before the reverse.
                    prev_route = route - idx - 1
                    return task(context, task_id=task_id, route=prev_route)
    else:
        # Otherwise, get the task flow entry and use the
        # task id and route to query the database.
        task_state_seqs = workflow_state.get('sequence') or []
        task_state_entry = task_state_seqs[task_state_entry_idx]
        route = task_state_entry['route']
        st2_ctx = context['__vars']['st2']
        workflow_execution_id = st2_ctx['workflow_execution_id']

        # Query the database by the workflow execution ID, task ID, and task route.
        instances = wf_db_access.TaskExecution.query(
            workflow_execution=workflow_execution_id,
            task_id=task_id,
            task_route=route)

    if not instances:
        message = 'Unable to find task execution for "%s".' % task_id
        raise exc.ExpressionEvaluationException(message)

    return format_task_result(instances)
Example #2
0
def task(context, task_id=None, route=None):
    instances = None

    try:
        current_task = workflow_functions._get_current_task(context)
    except:
        current_task = {}

    if task_id is None:
        task_id = current_task['id']

    if route is None:
        route = current_task.get('route', 0)

    try:
        workflow_state = context['__state'] or {}
    except KeyError:
        workflow_state = {}

    task_state_pointers = workflow_state.get('tasks') or {}
    task_state_entry_uid = constants.TASK_STATE_ROUTE_FORMAT % (task_id, str(route))
    task_state_entry_idx = task_state_pointers.get(task_state_entry_uid)

    # If unable to identify the task flow entry and if there are other routes, then
    # use an earlier route before the split to find the specific task.
    if task_state_entry_idx is None:
        if route > 0:
            current_route_details = workflow_state['routes'][route]
            # Reverse the list because we want to start with the next longest route.
            for idx, prev_route_details in enumerate(reversed(workflow_state['routes'][:route])):
                if len(set(prev_route_details) - set(current_route_details)) == 0:
                    # The index is from a reversed list so need to calculate
                    # the index of the item in the list before the reverse.
                    prev_route = route - idx - 1
                    return task(context, task_id=task_id, route=prev_route)
    else:
        # Otherwise, get the task flow entry and use the
        # task id and route to query the database.
        task_state_seqs = workflow_state.get('sequence') or []
        task_state_entry = task_state_seqs[task_state_entry_idx]
        route = task_state_entry['route']
        st2_ctx = context['__vars']['st2']
        workflow_execution_id = st2_ctx['workflow_execution_id']

        # Query the database by the workflow execution ID, task ID, and task route.
        instances = wf_db_access.TaskExecution.query(
            workflow_execution=workflow_execution_id,
            task_id=task_id,
            task_route=route
        )

    if not instances:
        message = 'Unable to find task execution for "%s".' % task_id
        raise exc.ExpressionEvaluationException(message)

    return format_task_result(instances)
Example #3
0
 def test_get_current_task(self):
     context = {'__current_task': {'id': 't1', 'route': 0}}
     self.assertDictEqual(funcs._get_current_task(context), context['__current_task'])
Example #4
0
 def test_get_current_task(self):
     context = {"__current_task": {"id": "t1", "route": 0}}
     self.assertDictEqual(funcs._get_current_task(context), context["__current_task"])