Main Content

addDependsOnRelationship

Class: padv.Process
Namespace: padv

Create dependency between two tasks or subprocesses

Syntax

addDependsOnRelationship(process,Source=dependentTaskOrSubprocess,Dependency=prerequisiteTaskOrSubprocess)
addDependsOnRelationship(___,Name=Value)

Description

addDependsOnRelationship(process,Source=dependentTaskOrSubprocess,Dependency=prerequisiteTaskOrSubprocess) specifies that in the process, the source depends on the dependency. The source does not run until after the dependency runs completely and has a status.

addDependsOnRelationship(___,Name=Value) specifies additional characteristics of the relationship by using one or more Name=Value arguments. For example, addDependsOnRelationship(p1,Source=t2,Dependency=t1,WhenStatus=["Pass","Fail"]) specifies that in process p1, task t2 depends on task t1 and that task t2 can only run after t1 runs completely and has a passing or failing task status.

Input Arguments

expand all

Process, specified as a padv.Process object.

Example: padv.Process("p1")

Task or subprocess that depends on the completion of a prerequisite task or subprocess, specified as either:

  • Task name, specified as a string

  • Task instance, specified as a padv.Task object

  • Subprocess name, specified as a string

  • Subprocess instance, specified as a padv.Subprocess object

Example: "TaskB"

Example: padv.Task("TaskB")

Example: padv.builtin.task.AnalyzeModelCode()

Task or subprocess that must run before a dependent task or subprocess, specified as either:

  • Task name, specified as a string

  • Task instance, specified as a padv.Task object

  • Subprocess name, specified as a string

  • Subprocess instance, specified as a padv.Subprocess object

Example: "TaskA"

Example: padv.Task("TaskA")

Example: padv.builtin.task.GenerateCode()

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: addDependsOnRelationship(p1,Source=t2,Dependency=t1,WhenStatus=["Pass","Fail"])

Option to control which prerequisite task iterations run, specified as a numeric or logical 1 (true) or 0 (false):

  • true — When the build system runs the dependencies, the build system runs only the task iterations that the tasks have in common.

  • false — When the build system runs the dependencies of a task, the build system runs all task iterations. This behavior is useful when you have a task that creates new project artifacts and a task that runs on each artifact in the project. The second task depends on all project artifacts generated by the first task.

For example, suppose you have two tasks: TaskA and TaskB:

  • TaskA runs on ModelA and ModelB.

  • TaskB runs only on ModelB and depends on TaskA.

If you run TaskB and:

  • IterationArtifactMatching is true, TaskA runs only on ModelB.

    Mouse pointing to run button for ModelB task iteration for TaskB. The Process Advisor app only highlights the ModelB task iteration in TaskA.

  • IterationArtifactMatching is false, TaskA runs on both ModelA and ModelB.

    Mouse pointing to run button for ModelB task iteration for TaskB. The Process Advisor app highlights both the ModelA and ModelB task iterations for TaskA.

Data Types: logical

Replace existing relationship, specified as a numeric or logical 0 (false) or 1 (true).

By default, if you define multiple relationships between the same tasks or subprocesses, the build system only uses the most recent relationship and ignores previous relationships. Setting the Override argument as 1 (true) makes sure that the current relationship replaces any existing relationship between the tasks or subprocesses.

Data Types: logical

Option to control when dependencies run, specified as either:

  • "Pass" — Only run the task or subprocess if the dependencies pass. For example, if TaskB depends on TaskA, TaskA needs to pass before TaskB runs. If TaskA fails or errors, TaskB does not run.

  • ["Pass","Fail"] — Only run the task or subprocess if the dependencies either pass or fail. For example, if TaskB depends on TaskA, TaskA needs to either pass or fail before TaskB runs. If TaskA errors, TaskB does not run.

  • ["Pass","Fail","Error"] — The task or subprocess runs, even if the dependencies fail or error. For example, if TaskB depends on TaskA, TaskA can pass, fail, or error and TaskB still runs.

Examples

expand all

In your process model, you can define multiple processes for different workflows and environments. A process consists of the tasks and subprocesses that you add to your padv.Process process by using the addTask and addSubprocess methods. To specify the relationships between tasks inside a specific process, use the addDependsOnRelationship and addRunsAfterRelationship methods.

Open the Process Advisor example project.

processAdvisorExampleStart

The model AHRS_Voter opens with the Process Advisor pane to the left of the Simulink® canvas.

In the Process Advisor pane, click the Edit process model button to open the processmodel.m file for the project.

Replace the contents of the processmodel.m file with the following example code. The code:

  • Defines two processes, processA and processB

  • Adds example tasks and subprocess to the processes by using the addTask and addSubprocess methods

  • Defines task relationships inside a specific process by using the addDependsOnRelationship and addRunsAfterRelationship methods

function processmodel(pm)
    % This function defines a process model for a project by setting up processes,
    % subprocesses, and tasks within those processes.

    arguments
        pm padv.ProcessModel
    end

    % --- Processes ---
    % Add processes to process model
    processA = pm.addProcess("A");
    processB = pm.addProcess("B");

    % --- Tasks ---
    % Create example tasks
    task1 = padv.Task("task1");
    task2 = padv.Task("task2");
    task3 = padv.Task("task3");
    taskA1 = padv.Task("taskA1");
    taskA2 = padv.Task("taskA2");
    taskB1 = padv.Task("taskB1");
    taskB2 = padv.Task("taskB2");

    % --- Subprocesses ---
    % Add subprocesses to parent process
    subprocessA = processA.addSubprocess("subprocessA"); % Add to process A
    subprocessB = processB.addSubprocess("subprocessB"); % Add to process B

    % --- Add Tasks to Processes ---
    processA.addTask(task1); % Add task1 to process A
    processA.addTask(task2); % Add task2 to process A
    processB.addTask(task1); % Reuse task1 in process B
    processB.addTask(task3); % Add task3 to process B

    % --- Add Tasks to Subprocesses ---
    subprocessA.addTask(taskA1); % Add taskA1 to subprocessA under process A
    subprocessA.addTask(taskA2); % Add taskA2 to subprocessA under process A
    subprocessB.addTask(taskB1); % Add taskB1 to subprocessB under process B
    subprocessB.addTask(taskB2); % Add taskB2 to subprocessB under process B

    % --- Add Relationships Between Tasks ---
    % In processA, task2 should run after task1
    processA.addRunsAfterRelationship(...
        Source = task2,...
        Predecessor = task1);
    % In processA, taskA2 depends on taskA1
    processA.addDependsOnRelationship(...
        Source = taskA2,...
        Dependency = taskA1);

end

In Process Advisor, refresh by clicking Refresh Tasks.

You can select which process you want to use from the Process gallery in the toolstrip. By default, processes appear in the order that you define them in the process model.

If you point to the run button for taskA2 in process A, Process Advisor highlights the dependency between taskA2 and taskA1.

Process Advisor Tasks column showing mouse pointing to taskA2

Go to top of page