Welcome to the new Golem Cloud Docs! 👋
Documentation
Go Language Guide
Accessing worker metadata

Accessing Worker Metadata

Golem workers can access their own and other worker's metadata.

In Go the worker metadata accessing functions have idiomatic Go wrappers in the Golem Go SDK.

Worker Metadata

Worker metadata is defined as the following types in the golemhost package:

type ComponentID uuid.UUID
 
type WorkerID struct {
	ComponentID ComponentID
	WorkerName  string
}
 
type WorkerMetadataEnvVar struct {
	Name  string
	Value string
}
 
type WorkerStatus int
 
const (
	WorkerStatusRunning = iota
	WorkerStatusIdle
	WorkerStatusSuspended
	WorkerStatusInterrupted
	WorkerStatusRetrying
	WorkerStatusFailed
	WorkerStatusExited
)
 
type WorkerMetadata struct {
	WorkerId         WorkerID
	Args             []string
	Env              []WorkerMetadataEnvVar
	Status           WorkerStatus
	ComponentVersion uint64
	RetryCount       uint64
}

Get Self Metadata

To access the metadata for the currently running worker use the golemhost.GetSelfMetadata function, which returns golemhost.WorkerMetadata:

import (
	"fmt"
 
	"github.com/golemcloud/golem-go/golemhost"
)
 
workerMetadata := golemhost.GetSelfMetadata()
fmt.Println(workerMetadata.WorkerId.WorkerName)

Get Other Worker's Metadata

Other worker's metadata can be accessed by using the golemhost.GetWorkerMetadata functions, which expects a golemhost.WorkerID, and returns *golemhost.WorkerMetadata:

import (
	"fmt"
 
	"github.com/google/uuid"
 
	"golem/component/go_default_comp"
)
 
workerMetadata := golemhost.GetWorkerMetadata(
	golemhost.WorkerID{
		ComponentID: golemhost.ComponentID(uuid.MustParse("d6520ae9-33c9-47e2-8fe1-0da0e6e568ac")),
		WorkerName:  "worker-1",
	},
)
if workerMetadata != nil {
	fmt.Printf("Worker status: %d\n", workerMetadata.Status)
} else {
	fmt.Printf("Worker not found")
}