Skip to content

Mastering Dependencies

rosaliafx edited this page Mar 29, 2015 · 8 revisions

Rosalia uses the notion of dependencies between tasks. If task A depends on tasks B and C then it's required that both B and C executed successfully in order to execute A. There are two ways of declaring dependencies with Rosalia:

Automatic dependencies tracking

Every time you use Linq for sharing task results, Rosalia tracks dependencies automatically. Let's look at the example from previous article:

protected override void RegisterTasks()
{
    var getVersionTask = Task(
        "getVersion", 
        () => {
            // ...
            return "v1.0.2".AsTaskResult();
        });

    var resolveAssemblyInfoTask = Task(
        "resolveAssemblyInfo", 
        context => {
            IFile file = context.WorkDirectory["Src"]["CommonAssemblyInfo.cs"];
            return file.AsTaskResult();
        });

    Task(
        "generateCommonAssembyInfo", 
        from version in getVersionTask                
        from pathToFile in resolveAssemblyInfoTask
        select new GenerateAssemblyInfo(pathToFile)   
        {
            Attributes = 
            {
                _ => new AssemblyProductAttribute("MyProduct"),
                _ => new AssemblyVersionAttribute(version),
                _ => new AssemblyFileVersionAttribute(version)
            }
        });
}

Dependencies graph for these tasks looks like this:

Rosalia sample dependencies graph

getVersion and resolveAssemblyInfo are independed so they placed on the same layer and could be executed simultaneously. generateCommonAssembyInfo, on the other hand, depends on both getVersion and resolveAssemblyInfo so it will be executed as soon as these two dependencies complete.

Manual dependencies declaration

It is possible to declare dependencies manually, using DependsOn behavior. DependsOn is a method of Rosalia.Core.Api.Workflow class that accept task future as an argument and returns ITaskBehavior that you can pass to dependant task declaration:

protected override void RegisterTasks()
{
   var taskA = Task("A", /**/);

   var taskB = Task(
       "B",
       new MyTask(),
       DependsOn(taskA)); // <--
}

Dependencies graph for these declaration:

Rosalia manual dependencies graph

It is possible to mix Automatic and Manual declaratios:

Task(
    "generateCommonAssembyInfo", 

    from version in getVersionTask                
    from pathToFile in resolveAssemblyInfoTask
    select new GenerateAssemblyInfo(pathToFile)   
    {
        Attributes = 
        {
            _ => new AssemblyProductAttribute("MyProduct"),
            _ => new AssemblyVersionAttribute(version),
            _ => new AssemblyFileVersionAttribute(version)
        }
    },

    DependsOn(clearArtifacts),  // <--
    DependsOn(someOtherTask));  // <--