Main Content

runsAfter

Specify preferred execution order for tasks

    Description

    runsAfter(taskObj,predecessors) specifies a preferred execution order for tasks. If possible, the build system runs the predecessor tasks, specified by predecessors, before the task represented by taskObj.

    This function requires CI/CD Automation for Simulink Check.

    example

    runsAfter(___,Name=Value) specifies how the build system handles the preferred execution order 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.

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

    runsAfter(taskA, taskB)
    runsAfter(taskB, taskA) % build system only uses this relationship

    example

    Examples

    collapse all

    Use the runsAfter function to specify that one task should run after another task.

    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
    
        FirstTask = padv.Task("FirstTask");
        SecondTask = padv.Task("SecondTask");
    
        runsAfter(SecondTask,FirstTask);
    
        addTask(pm,FirstTask);
        addTask(pm,SecondTask);
        
    end

    This code uses padv.Task to create two task objects: FirstTask and SecondTask.

    The object function runsAfter specifies that SecondTask should run after FirstTask.

    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 toolstrip, click the Run All button. You can see that SecondTask runs after FirstTask.

    Input Arguments

    collapse all

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

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

    Tasks that should run before taskObj runs, specified as either:

    • The name of a task, specified as a string or character vector.

    • A padv.Task object.

    Example: runsAfter(SecondTask,"FirstTask")

    Example: runsAfter(SecondTask,FirstTask)

    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: runsAfter(SecondTask,FirstTask,StrictOrdering=true)

    Setting that controls which predecessor task iterations run, specified as a numeric or logical 1 (true) or 0 (false):

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

    • false — When the build system runs the predecessor 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 should run after all project artifacts are generated by the first task.

    For example, suppose you have two tasks: FirstTask and SecondTask:

    • FirstTask runs on ModelA and ModelB.

    • SecondTask runs only on ModelB and should run after on FirstTask.

    If you run SecondTask and:

    • IterationArtifactMatching is true, FirstTask runs only on ModelB.

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

    Example: runsAfter(SecondTask,FirstTask,IterationArtifactMatching=false)

    Data Types: logical

    Setting that controls whether the build system ignores circular relationships between tasks, specified as a numeric or logical 0 (false) or 1 (true). By default, if you specify a circular relationship between tasks, the build system ignores the relationship. For example, if you specify both runsAfter(SecondTask,FirstTask) and runsAfter(FirstTask,SecondTask), the build system ignores the runsAfter relationship.

    If you specify StrictOrdering as true, the build system generates an error when you try to run tasks that have a circular relationship.

    Example: runsAfter(SecondTask,FirstTask,StrictOrdering=true)

    Data Types: string

    Tips

    In your process model, you can specify the relationship between tasks as either a dependsOn or runsAfter relationship. If your task depends on inputs or results from another task to run successfully, specify the relationship by using the dependsOn method instead. For more information, see Define Task Relationships.