hosting

package
v0.42.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const ShutdownTimeout = time.Second * 10

Variables

This section is empty.

Functions

func RunWithInterrupts

func RunWithInterrupts(ctx context.Context, host *Host) error

RunWithInterrupts runs the given host, and handles shutdown gracefully when a console interrupt is received.

Types

type Host

type Host struct {
	// Slice of services to run. Started in order.
	Services []Service

	// LoggerValues is key-value-pairs passed to .WithValues to initialize the logger for the host.
	LoggerValues []any

	// TimeoutFunc allows you to control the timeout behavior for testing
	TimeoutFunc func()
}

Host manages the lifetimes and starting of Services.

func (*Host) Run

func (host *Host) Run(ctx context.Context, serviceErrors chan<- LifecycleMessage) error

Run starts all services in the host, waits for them to finish, and returns an error if any of them fail or if a timeout is reached.

func (*Host) RunAsync

func (host *Host) RunAsync(ctx context.Context) (<-chan error, <-chan LifecycleMessage)

RunAsync runs the host's services asynchronously and returns two channels, one for errors and one for lifecycle messages, which can be used to monitor the progress of the services.

type LifecycleMessage

type LifecycleMessage struct {
	Name string
	Err  error
}

LifecycleMessage is a message returned when a service terminates.

type Service

type Service interface {
	// Name returns the name of the service.
	Name() string

	// Run runs the service as a blocking operation.
	Run(ctx context.Context) error
}

Service is an abstraction for a long-running subsystem of the RP.

Jump to

Keyboard shortcuts

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