Tasks

Terrabuild aims at scheduling tasks to complete goals (which are targets). For this, Terrabuild creates a graph with all automatically discovered projects, targets and project dependencies. For each tasks (which are nodes of this graph), Terrabuild has to decide what to do.

For that, Terrabuild relies on a cache (either local or remote). A cache is driven by a key: this key (which is the unique identifier of the task) is built using:

  • hash of files of the project
  • project dependencies
  • variables used for task
ℹ️
Note that unless you are using specific information from commit (like terrabuild.head_commit or terrabuild.branch_or_tag variables), this key is unique across branches. This is a really major concept since this enables important build optimizations.

Once the key has been computed, Terrabuild uses the target configuration and following decision tree to decide:

flowchart LR

classDef start fill:black
classDef build stroke-width:4px,stroke:black,fill:white
classDef restore stroke-width:4px,stroke:black,fill:white
classDef decision stroke:black
classDef use-cache fill:#b0f1da,stroke:black,stroke-dasharray: 10 2,rx:10,ry:10
classDef dynamic fill:#CEB1FB,stroke:black,stroke-width:1px,stroke-dasharray: 5 2,rx:10,ry:10

start((" "))
force(Force ?)

restore((Restore))
build((Build))

dependency(Dependency rebuilt ?)
cache(In cache ?)
failed(Failed ?)
retry(Retry ?)
ephemeral(Ephemeral ?)


start --> force

force -- yes --> build
force -- no --> cache

cache -- yes --> retry
cache -- no --> build

retry -- no --> dependency
retry -- yes --> ephemeral

ephemeral -- yes --> build
ephemeral -- no --> failed

failed -- no --> dependency
failed -- yes --> build

dependency -- yes --> build
dependency -- no --> restore

class start start
class build build
class restore restore
class force,cacheable,younger,retry,ext,state-changed decision
class use-cache use-cache
class dynamic dynamic
ConditionDescription
Forceeither --force or rebuild (target) enabled
In cachetarget is available in cache
Retry--retry enabled
Ephemeraltarget is configured as ephemeral
Failedprevious build has failed
Dependency rebuilta dependency has been rebuilt for some reasons

Decision is either Build or Restore leading to a new state for the task. Note that if task is built (or built again), this triggers, in turn, build of dependent nodes.

In all cases, new state is stored in local cache. If connected to a backend, task state is uploaded and can be used in further executions.

Last updated on