cluster

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultService           = "runa"
	DefaultHeartbeatInterval = 10 * time.Second
	DefaultTTL               = 30 * time.Second
)

Variables

This section is empty.

Functions

func Provider

func Provider(items ...Option) runaprovider.Provider

Provider registers optional cluster heartbeat support.

Types

type Driver

type Driver interface {
	Name() string
	Register(ctx context.Context, instance Instance) error
	Heartbeat(ctx context.Context, id string, status Status) error
	Unregister(ctx context.Context, id string) error
	Instances(ctx context.Context, service string) ([]Instance, error)
	Close(ctx context.Context) error
}

Driver stores cluster instance heartbeats.

func MemoryDriver

func MemoryDriver() Driver

MemoryDriver creates an in-process cluster driver.

type DriverRegistry added in v0.1.2

type DriverRegistry struct {
	// contains filtered or unexported fields
}

DriverRegistry stores named cluster drivers contributed by driver subpackages.

func NewDriverRegistry added in v0.1.2

func NewDriverRegistry() *DriverRegistry

NewDriverRegistry creates a driver registry with the default memory driver.

func (*DriverRegistry) Driver added in v0.1.2

func (registry *DriverRegistry) Driver(name string) Driver

Driver returns a cluster driver by name.

func (*DriverRegistry) Register added in v0.1.2

func (registry *DriverRegistry) Register(driver Driver)

Register stores a cluster driver by its own name.

func (*DriverRegistry) Shutdown added in v0.1.2

func (registry *DriverRegistry) Shutdown(ctx context.Context) error

Shutdown closes registered drivers when the registry is managed by DI.

type Instance

type Instance struct {
	ID          string        `json:"id"`
	Service     string        `json:"service"`
	Env         string        `json:"env"`
	Version     string        `json:"version"`
	Hostname    string        `json:"hostname"`
	PID         int           `json:"pid"`
	Addr        string        `json:"addr,omitempty"`
	Status      Status        `json:"status"`
	StartedAt   time.Time     `json:"started_at"`
	HeartbeatAt time.Time     `json:"heartbeat_at"`
	TTL         time.Duration `json:"ttl"`
	Meta        core.Map      `json:"meta,omitempty"`
}

Instance describes one running app process.

func Info

func Info(ctx context.Context) []Instance

Info returns active default cluster instances when cluster is enabled.

type Option

type Option func(*options)

Option configures the cluster provider.

func Addr

func Addr(value string) Option

Addr sets the public or internal instance address.

func DriverWith

func DriverWith(driver Driver) Option

DriverWith sets the cluster state driver.

func Env

func Env(value string) Option

Env sets the environment name.

func HeartbeatInterval

func HeartbeatInterval(value time.Duration) Option

HeartbeatInterval sets heartbeat interval.

func ID

func ID(value string) Option

ID sets the instance id.

func Meta

func Meta(key string, value any) Option

Meta sets instance metadata.

func Service

func Service(value string) Option

Service sets the service name.

func TTL

func TTL(value time.Duration) Option

TTL sets stale instance timeout.

func UseDriver

func UseDriver(name string) Option

UseDriver selects a configured cluster driver by name.

func Version

func Version(value string) Option

Version sets the application version.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry stores cluster state for one app instance.

func Default

func Default() *Registry

Default returns the optional default cluster runtime.

func NewRegistry

func NewRegistry(ctx runaprovider.Context, opts options) (*Registry, error)

NewRegistry creates a cluster runtime.

func RegistryOf

func RegistryOf(ctx runaprovider.Context) *Registry

RegistryOf returns the optional cluster runtime from provider context.

func (*Registry) Boot

func (runtime *Registry) Boot(ctx context.Context, app runaprovider.Context) error

func (*Registry) Init

func (*Registry) Instance

func (runtime *Registry) Instance() Instance

Instance returns this runtime instance snapshot.

func (*Registry) Instances

func (runtime *Registry) Instances(ctx context.Context, service ...string) ([]Instance, error)

Instances returns active cluster instances.

func (*Registry) Name

func (runtime *Registry) Name() string

func (*Registry) Register

func (runtime *Registry) Register(context.Context, runaprovider.Context) error

func (*Registry) Shutdown

func (runtime *Registry) Shutdown(ctx context.Context, app runaprovider.Context) error

type Status

type Status string

Status describes instance state.

const (
	StatusStarting Status = "starting"
	StatusRunning  Status = "running"
	StatusDraining Status = "draining"
	StatusStopped  Status = "stopped"
)

Jump to

Keyboard shortcuts

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