app

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultShutdownTimeout stays under the supervisor's grace period before
	// the kill, which for `docker stop` defaults to 10s.
	DefaultShutdownTimeout = 8 * time.Second

	DefaultDrainTimeout = 7 * time.Second
	DefaultStopTimeout  = 1 * time.Second
)

Variables

View Source
var ErrDrainTimeout = errors.New("app: modules still running at the shutdown deadline")

ErrDrainTimeout means a module ignored its context and was abandoned.

Functions

func Exec added in v0.6.0

func Exec(ctx context.Context, modules []Module, fn func(i do.Injector) error, opts ...Option) error

Types

type App

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

func New

func New(ctx context.Context, modules []Module, opts ...Option) (*App, error)

func (*App) Injector

func (a *App) Injector() do.Injector

func (*App) Run

func (a *App) Run(ctx context.Context) error

func (*App) Shutdown

func (a *App) Shutdown(ctx context.Context) error

type DrainBudget

type DrainBudget time.Duration

DrainBudget is how much time a Run has to return once its context is cancelled. A module that drains inside Run should read it before it provides, to check that its own drain time fits.

func (DrainBudget) String

func (b DrainBudget) String() string

type Module

type Module interface {
	Name() string
}

type Option

type Option func(*options)

func WithDrainTimeout

func WithDrainTimeout(d time.Duration) Option

WithDrainTimeout bounds how long the runnable modules have to return once their context is cancelled, after which they are abandoned. WithDrainTimeout and WithStopTimeout together have to fit inside WithShutdownTimeout.

func WithShutdownTimeout

func WithShutdownTimeout(d time.Duration) Option

WithShutdownTimeout sets the ceiling WithDrainTimeout and WithStopTimeout have to fit inside, and comes from the supervisor's grace period rather than anything this process decides.

func WithStopTimeout

func WithStopTimeout(d time.Duration) Option

WithStopTimeout bounds releasing what the modules hold, on its own budget rather than what draining left over. WithDrainTimeout and WithStopTimeout together have to fit inside WithShutdownTimeout.

type Provider

type Provider interface {
	Module
	Provide(ctx context.Context, i do.Injector) error
}

type Runner

type Runner interface {
	Module
	Run(ctx context.Context) error
}

type Stopper

type Stopper interface {
	Module
	Stop(ctx context.Context) error
}

Jump to

Keyboard shortcuts

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