question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conditional task dependencies

See original GitHub issue

I was just trying to figure out a way to do conditional dependencies between tasks, particularly as a means to get incremental build behavior.

It’s not directly supported through the task DSL, but I figured I’d see if anyone has ideas on how I might achieve this. If not, maybe this would be a nice enhancement 😄

Here’s a simplified example of what I’m trying to do:

Let’s say I have a Build task and a Package task. I only want to run the Build task if my bin is empty (or older than the source files, or whatever). Otherwise, I’ll just package the artifacts that are already in the bin.

Obviously I can set up a WithCriteria on the Build task, but I don’t really want to the Build task to be responsible for that, as I don’t always want that rule to be applied every time the Build task is invoked – I’d rather apply that condition contextually.

I actually expected that if a Task’s WithCriteria isn’t satisfied, that the tasks it depends on would not be invoked. That doesn’t seem to be the case, though. The dependencies always get invoked, and only the task with the unsatisfied Criteria gets skipped.

Any thoughts?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
reisenbergercommented, Jan 12, 2018

To solve a scenario similar to that outlined by @jonstelly - a whole group of tasks grouped under the umbrella “package”, with one bool controlling go/no-go for that group - I did the following, for now:

Task("_ConditionallyPackage")
    .WithCriteria(() => package)
    .Does(() => RunTarget("_Package"));

In wider context:

Task("Build")
    .IsDependentOn("_BuildAndTest")
    .IsDependentOn("_ConditionallyPackage");

Task("_BuildAndTest")
    .IsDependentOn("__Clean")
    .IsDependentOn("__RestoreNugetPackages")
    .IsDependentOn("__BuildSolutions")
    .IsDependentOn("__RunTests");

Task("_Package")
    .IsDependentOn("__CopyOutputToNugetFolder")
    .IsDependentOn("__CreateNugetPackage");

Task("_ConditionallyPackage")
    .WithCriteria(() => package) // bool value package calculated somewhere earlier ...
    .Does(() => RunTarget("_Package"));

Not offering this as a recommendation, just an example of another workround. I agree that some native syntax would be better.

( @patriksvensson , it was good to meet you at tretton37 in November 😄 )

2reactions
jden123commented, Dec 23, 2018

@devlead, thank you for your feedback. If subtask can lead to main task condition fail that can add complexity.

In my case I have task “tree” where small tasks(actions) are grouped into big task that are group into the biggest 😃

Task -> Task1(condition 1) -> Subtask11
                           -> Subtask12
       
     -> Task2(condition 2) -> Subtask21
                           -> Subtask22

Now, as a workaround, I build task based on criterias like

var task = Task("Task");

if (doTask1)
{
    task.IsDependentOn("Task1");
}

if (doTask2)
{
    task.IsDependentOn("Task2");
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Airflow setting conditional dependency
In the below dependency I setup upstream as a list of [print-conf-2, print-conf-1] expecting it to have both the task as upstream however ......
Read more >
14. Tasks Dependencies in Airflow | by Najma Bader
Conditional dependencies allow you to make certain tasks run only if some conditions are met (e.g. the dataset is available, the execution ......
Read more >
Manage task and task group dependencies in Airflow
Learn how to manage dependencies between tasks and TaskGroups in Apache Airflow, ... rules is if your DAG contains conditional logic such as...
Read more >
How to Configure Conditional Dependencies in Gradle
Learn how to configure conditional dependencies in a Gradle project. ... Now, let's run the dependencies task to see which provider module ...
Read more >
Cookbook » Conditional Tasking
A weak dependency is a preceding link from a condition task to another task. The number of dependents of a task is the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found