Main Content

dependsOn

Create dependency between tasks

    Description

    dependsOn(taskObj,predecessors) creates a dependency between taskObj and predecessors. taskObj runs only after the tasks specified by predecessors run and return a task status.

    example

    dependsOn(___,Name=Value) specifies how the build system handles predecessors using one or more Name=Value arguments.

    Note

    You can specify the relationship between two tasks as either a dependsOn relationship or a runsAfter relationship, but not both.

    By default, if you define multiple relationships between the same tasks, the build system only uses the most recent relationship and ignores previous relationships. For example:

    dependsOn(taskA, taskB)
    dependsOn(taskB, taskA) % build system only uses this relationship
    However, you can use the Override argument to explicitly replace an existing relationship with a new relationship.

    Examples

    collapse all

    Use the dependsOn function to create a dependency between two tasks in a process model.

    Open the Process Advisor example project.

    processAdvisorExampleStart

    Open the processmodel.m file. The file is at the root of the project.

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

    function processmodel(pm)
        arguments
            pm padv.ProcessModel
        end
    
        TaskA = padv.Task("TaskA");
        TaskB = padv.Task("TaskB");
    
        dependsOn(TaskB,TaskA);
    
        addTask(pm,TaskA);
        addTask(pm,TaskB);
        
    end

    This code uses padv.Task to create two task objects: TaskA and TaskB.

    The object function dependsOn specifies that TaskB depends on TaskA.

    The function addTask adds the task objects to the padv.ProcessModel object.

    Open the Process Advisor app. In the MATLAB® Command Window, enter:

    processAdvisorWindow

    In the Tasks column, point to the run button for TaskB. The Process Advisor app automatically highlights both tasks since TaskA is a predecessor task. If you click the run button for TaskB, TaskA will run before TaskB.

    TaskB depends on TaskA. Both tasks are highlighted in the Process Advisor app.

    Input Arguments

    collapse all

    Task object that represents a task, specified as a padv.Task object.

    Example: myTaskObj = padv.Task("myTask");

    Tasks or subprocesses that need to run before this task runs, specified as either the:

    • Name of a task, specified as a string or character vector

    • padv.Task object

    • Array of task names

    • Array of padv.Task objects

    Example: dependsOn(TaskB,"TaskA")

    Example: dependsOn(TaskB,TaskA)

    Example: dependsOn(TaskC,[TaskA,TaskB])

    Example: dependsOn(TaskC,["TaskA","TaskB"])

    Data Types: char | string

    Name-Value Arguments

    collapse all

    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: dependsOn(TaskB,TaskA,WhenStatus=["Pass","Fail"])

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

    • true — The build system runs only iterations that the predecessor and source have in common.

    • false — The build system runs all predecessor 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.

    Example: dependsOn(TaskB,TaskA,IterationArtifactMatching=false)

    Data Types: logical

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

    By default, if you define multiple relationships between the same tasks, 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 task relationship replaces any existing relationship between the tasks.

    Data Types: logical

    Option to control when the source task or subprocess runs, specified as either "Pass", "Fail", "Error", or a combination of those options.

    For example, you can specify ["Pass","Fail"] to instruct the build system to only run the source if the predecessors pass or fail. By default, the source only runs if the predecessors pass.

    Example: dependsOn(TaskB,TaskA,WhenStatus=["Pass","Fail"])

    Data Types: string

    Tips

    In your process model, you can specify the relationship between tasks as either a dependsOn or runsAfter relationship. If you want to specify a preferred task execution order for tasks that do not depend on each other, you can specify your preferred task execution order by using the runsAfter method instead. For more information, see Define Task Relationships.