-
Notifications
You must be signed in to change notification settings - Fork 6
Dependencies
Tasks can have other tasks as dependencies. So if a dependency is defined, this dependency is run before the actual task. gotaskr makes sure that each task is only run once, even if it is defined in multiple other tasks. To define a depencency, use the DependsOn
while registering a task.
A simple example would be Build
-> Test
-> Deploy
To define this in gotaskr, this would look like:
gotaskr.Task("Build", buildFunc)
gotaskr.Task("Test", testFunc).DependsOn("Build")
gotaskr.Task("Deploy", deployFunc).DependsOn("Test")
A task can also have multiple dependencies. In that case, they are executed in the order they are added as dependency.
The following example will run all tasks in that order.
Sidenote1: If each task has dependencies defined as above, then Deploy
would be enough but I'm sure you get the point.
Sidenote2: goext.Noop
is a special constant which represends a no-operation function that can be used for tasks without own logic.
gotaskr.Task("Full-Build", goext.Noop).DependsOn("Build", "Test", "Deploy")
A reverse dependency can be defined with the DependeeOf
method while registering a task.
Example:
gotaskr.Task("Build", buildFunc).DependeeOf("Test")
gotaskr.Task("Test", testFunc)
Sometimes a task should start another task after it is finished. This can be defined with Then
while registering or with gotaskr.AddFollowupTask
while running a task.
Examples:
// With "Then"
gotaskr.Task("Build", buildFunc).Then("UploadBuildLog")
gotaskr.Task("UploadBuildLog", uploadFunc)
// With "AddFollowupTask"
gotaskr.Task("Build", func() error {
err := buildFunc
if err != nil {
gotaskr.AddFollowupTask("UploadBuildLog")
}
return err
)
gotaskr.Task("UploadBuildLog", uploadFunc)
Sometimes it is needed to run a task without its dependencies or dependees.
For this, the exclusive
argument can be passed. This makes sure that only the given target is run without and dependencies before or after.
Example:
go run . --target Test -e
# or
go run . --target Test --exclusive