Clusters
Use clusters to group runners, target job execution, and control where workflow releases are deployed.
A cluster determines where workflow tasks can run. When you submit a job, its root task is submitted to a cluster, and only runners assigned to that cluster can claim it.
By default, subtasks are submitted to the same cluster as their parent task. Task code can submit individual subtasks to other clusters when a workflow needs to execute across different environments.
Use Cases
Use clusters to organize runners and workflow release deployments into logical groups:
- Targeting specific runners or hardware (such as GPU machines or on-premises hosts) for a job or subtask
- Separating environments such as development, staging, and production
- Scoping environment variables and secrets per environment without rebuilding workflow code
- Deploying different workflow releases to different environments
Assigning runners and deployments
Every runner belongs to one cluster. Assign a direct runner by passing a cluster slug in SDK code, or start a release runner with tilebox runner start --cluster <cluster-slug>. If no cluster is specified, Tilebox assigns the runner to the default cluster.
For release runners, cluster membership also determines which deployed workflow releases and managed environment variables the runner loads. See Cluster Deployments and Environment variables & secrets for operational details.
Default Cluster
Each organization has a default cluster created automatically. Tilebox uses it whenever no cluster is specified when starting a runner, deploying a release, or submitting a job.
Managing Clusters
Before starting a runner or submitting a job to a custom cluster, create it with the CLI (tilebox cluster create <name>) or through the Python or Go SDK.
To manage clusters from code, instantiate a cluster client using the clusters method on the workflows client.
Instantiating a Clusters Client
from tilebox.workflows import Client
client = Client()
clusters = client.clusters()import "github.com/tilebox/tilebox-go/workflows/v1"
client := workflows.NewClient()
clusterClient := client.ClustersCreating a Cluster
To create a cluster, use the create method on the cluster client and provide a name for the cluster.
Creating a Cluster
cluster = clusters.create("testing")
print(cluster)cluster, err := client.Clusters.Create(ctx, "testing")
if err != nil {
slog.Error("failed to create cluster", slog.Any("error", err))
return
}
fmt.Println(cluster)Output
Cluster(slug='testing-CvufcSxcC9SKfe', display_name='testing')&{testing-CvufcSxcC9SKfe testing}Cluster Slug
Each cluster has a unique identifier, combining the cluster’s name and an automatically generated identifier. Use this slug to reference the cluster for other operations, like submitting a job or subtasks.
Listing Clusters
To list all available clusters, use the all method:
Listing Clusters
all_clusters = clusters.all()
print(all_clusters)clusters, err := client.Clusters.List(ctx)
if err != nil {
slog.Error("failed to list clusters", slog.Any("error", err))
return
}
for _, cluster := range clusters {
fmt.Println(cluster)
}Output
[Cluster(slug='testing-CvufcSxcC9SKfe', display_name='testing'),
Cluster(slug='production-EifhUozDpwAJDL', display_name='Production')]&{testing-CvufcSxcC9SKfe testing}
&{production-EifhUozDpwAJDL Production}Fetching a Specific Cluster
To fetch a specific cluster, use the find method and pass the cluster’s slug:
Fetching a Cluster
cluster = clusters.find("testing-CvufcSxcC9SKfe")
print(cluster)cluster, err := client.Clusters.Get(ctx, "testing-CvufcSxcC9SKfe")
if err != nil {
slog.Error("failed to get cluster", slog.Any("error", err))
return
}
fmt.Println(cluster)Output
Cluster(slug='testing-CvufcSxcC9SKfe', display_name='testing')&{testing-CvufcSxcC9SKfe testing}Deleting a Cluster
To delete a cluster, use the delete method and pass the cluster’s slug:
Deleting a Cluster
clusters.delete("testing-CvufcSxcC9SKfe")err := client.Clusters.Delete(ctx, "testing-CvufcSxcC9SKfe")Jobs Across Different Clusters
When submitting a job, you need to specify which cluster the job’s root task should be executed on. This allows you to direct the job to a specific set of runners. By default, all sub-tasks within a job are also submitted to the same cluster, but this can be overridden to submit sub-tasks to different clusters if needed. See the example below for a job that spans across multiple clusters.
Multi-Cluster Workflow Example
from tilebox.workflows import Task, ExecutionContext, Client
class MultiCluster(Task):
def execute(self, context: ExecutionContext) -> None:
# this submits a task to the same cluster as the one currently executing this task
same_cluster = context.submit_subtask(DummyTask())
other_cluster = context.submit_subtask(
DummyTask(),
# this task runs only on a runner in the "other-cluster" cluster
cluster="other-cluster-As3dcSb3D9SAdK",
# dependencies can be specified across clusters
depends_on=[same_cluster],
)
class DummyTask(Task):
def execute(self, context: ExecutionContext) -> None:
pass
# submit a job to the "testing" cluster
client = Client()
job_client = client.jobs()
job = job_client.submit(
"my-job",
MultiCluster(),
cluster="testing-CvufcSxcC9SKfe",
)package main
import (
"context"
"github.com/tilebox/tilebox-go/workflows/v1"
"github.com/tilebox/tilebox-go/workflows/v1/job"
"github.com/tilebox/tilebox-go/workflows/v1/subtask"
)
type MultiCluster struct{}
func (t *MultiCluster) Execute(ctx context.Context) error {
// this submits a task to the same cluster as the one currently executing this task
sameCluster, err := workflows.SubmitSubtask(ctx, &DummyTask{})
if err != nil {
return err
}
otherCluster, err := workflows.SubmitSubtask(
ctx,
&DummyTask{},
// this task runs only on a runner in the "other-cluster" cluster
subtask.WithClusterSlug("other-cluster-As3dcSb3D9SAdK"),
// dependencies can be specified across clusters
subtask.WithDependencies(sameCluster),
)
if err != nil {
return err
}
_ = otherCluster
return nil
}
type DummyTask struct{}
func main() {
ctx := context.Background()
client := workflows.NewClient()
// submit a job to the "testing" cluster
_, _ = client.Jobs.Submit(
ctx,
"my-job",
[]workflows.Task{
&MultiCluster{},
},
job.WithClusterSlug("testing-CvufcSxcC9SKfe"),
)
}This workflow requires at least two runners to complete. One must be in the “testing” cluster, and the other must be in the “other-cluster” cluster.
If no runners are available in the “other-cluster,” the task submitted to that cluster will remain queued until a runner is available.
It won’t execute on a runner in the “testing” cluster, even if that runner has the DummyTask registered.