-
Notifications
You must be signed in to change notification settings - Fork 1
Mastering Dependencies
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:
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:
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.
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:
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)); // <--
Writing Tasks
- Creating a Workflow
- Defining Tasks
- Share State accross Tasks
- Mastering Dependencies
- Using result transformers
- Using Subflows to organize tasks
- Tasks Preconditions
- Recovering failure results
- Declaring dynamic tasks
- Creating Custom Tasks
Running Tasks
API
Tasklib