tilebox

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2025 License: MIT Imports: 0 Imported by: 0

README

Tilebox Logo

Documentation | Console | Discord

Tilebox Go Library

This repository contains the Go library for Tilebox.

Getting Started

Installation

Run the following command to add the library to your project:

go get github.com/tilebox/tilebox-go

For Tilebox datasets type generation, you will need to install tilebox-generate command-line tool.

Examples

For examples on how to use the library, see the examples directory.

Usage

Writing a Task

Here we define a simple task that prints "Hello World!" to the console:

package helloworld

import (
	"context"
	"log/slog"

	"github.com/tilebox/tilebox-go/workflows/v1"
)

type HelloTask struct {
	Name string // You can add any fields you need to the task struct.
}

// The Execute method isn't needed to submit a task but is required to run a task.
func (t *HelloTask) Execute(context.Context) error {
	slog.Info("Hello World!", "Name", t.Name)
	return nil
}

// The Identifier method is optional and will be generated if not provided.
func (t *HelloTask) Identifier() workflows.TaskIdentifier {
	return workflows.NewTaskIdentifier("hello-world", "v1.0")
}
Submitting a Job

Here we create a Workflows client and submit a job with a single task:

package main

import (
	"context"
	"log/slog"
	"os"

	"github.com/tilebox/tilebox-go/workflows/v1"
)

type HelloTask struct {
	Name string
}

func main() {
	ctx := context.Background()

	client := workflows.NewClient()

	cluster, err := client.Clusters.Get(ctx, "testing-4qgCk4qHH85qR7")
	if err != nil {
		slog.ErrorContext(ctx, "failed to get cluster", slog.Any("error", err))
		return
	}

	job, err := client.Jobs.Submit(ctx, "hello-world", cluster,
		[]workflows.Task{
			&HelloTask{
				Name: "Tilebox",
			},
		},
	)
	if err != nil {
		slog.ErrorContext(ctx, "Failed to submit job", slog.Any("error", err))
		return
	}

	slog.InfoContext(ctx, "Job submitted", slog.String("job_id", job.ID.String()))
}
Running a Worker

Here we create a TaskRunner and run a worker that is capable of executing HelloTask tasks:

package main

import (
	"context"
	"log/slog"
	"os"

	"github.com/tilebox/tilebox-go/workflows/v1"
)

type HelloTask struct {
	Name string
}

// The Execute method is required to run a task.
func (t *HelloTask) Execute(context.Context) error {
	slog.Info("Hello World!", "Name", t.Name)
	return nil
}

func main() {
	ctx := context.Background()

	client := workflows.NewClient()

	cluster, err := client.Clusters.Get(ctx, "testing-4qgCk4qHH85qR7")
	if err != nil {
		slog.ErrorContext(ctx, "failed to get cluster", slog.Any("error", err))
		return
	}

	runner, err := client.NewTaskRunner(cluster)
	if err != nil {
		slog.ErrorContext(ctx, "failed to create task runner", slog.Any("error", err))
		return
	}

	err = runner.RegisterTasks(&HelloTask{})
	if err != nil {
		slog.ErrorContext(ctx, "failed to register tasks", slog.Any("error", err))
		return
	}

	runner.RunForever(context.Background())
}

Documentation

Overview

Package tilebox is the Go client for Tilebox.

Usage:

import "github.com/tilebox/tilebox-go/datasets/v1" // When using Datasets
import "github.com/tilebox/tilebox-go/workflows/v1" // When using Workflows
import "github.com/tilebox/tilebox-go/grpc" // When using gRPC helpers
import "github.com/tilebox/tilebox-go/observability" // When using observability helpers
import "github.com/tilebox/tilebox-go/observability/logger" // When using logging helpers
import "github.com/tilebox/tilebox-go/observability/tracer" // When using tracing helpers
import "github.com/tilebox/tilebox-go/query" // When using query helpers

To construct a client:

client := datasets.NewClient()

List all datasets:

datasets, err := client.Datasets(ctx)

For examples on how to use the library, see the examples directory.

Directories

Path Synopsis
datasets
v1
Package datasets provides a client for interacting with Tilebox Datasets.
Package datasets provides a client for interacting with Tilebox Datasets.
examples
datasets/ingest command
datasets/query command
protogen
workflows
v1
Package workflows provides a client for interacting with Tilebox Workflows.
Package workflows provides a client for interacting with Tilebox Workflows.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL