processruntime

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package processruntime 提供进程启动与关闭编排的基础机制。

该包只表达通用运行时生命周期能力,包括:

  • 按注册顺序执行关闭钩子的 Lifecycle。
  • 并发运行一组长跑服务并返回首个错误的 RunGroup。
  • 按阶段顺序准备进程状态的泛型 Runner。

业务项目可以把具体的 HTTP/gRPC 服务、消息订阅器、调度器等装配为 ServiceRunner 或 Stage,但不应把业务语义放入本包。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lifecycle

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

Lifecycle 收集关闭钩子,并按注册顺序执行。

func (*Lifecycle) AddShutdownHook

func (l *Lifecycle) AddShutdownHook(name string, run func() error)

AddShutdownHook 注册一个关闭钩子。

func (Lifecycle) Len

func (l Lifecycle) Len() int

Len 返回当前已注册的关闭钩子数量。

func (Lifecycle) Run

func (l Lifecycle) Run(onError func(name string, err error))

Run 按顺序执行所有关闭钩子。 单个钩子的错误会通过 onError 汇报,但不会阻止后续钩子继续执行。

type RunGroup

type RunGroup struct {
	StartShutdown func() error
	Services      []ServiceRunner
}

RunGroup 启动一组长跑服务,并返回首个服务错误。

func (RunGroup) Run

func (g RunGroup) Run() error

Run 先启动关闭管理器,再并发运行所有服务。

type Runner

type Runner[S any, P any] struct {
	State         *S
	Stages        []Stage[S]
	BuildPrepared func(*S) P
}

Runner 按顺序执行阶段,并在全部成功后构建 prepared 输出。

func (Runner[S, P]) Run

func (r Runner[S, P]) Run() (P, string, error)

Run 按顺序执行阶段,并返回 prepared 输出、失败阶段名称和错误。

type ServiceRunner

type ServiceRunner struct {
	Name string
	Run  func() error
}

ServiceRunner 描述一个长跑服务。

type ShutdownHook

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

ShutdownHook 是一个带名字的关闭钩子。

func (ShutdownHook) Name

func (h ShutdownHook) Name() string

Name 返回关闭钩子的名称。

func (ShutdownHook) Run

func (h ShutdownHook) Run() error

Run 执行关闭钩子;未配置执行函数时直接返回 nil。

type Stage

type Stage[S any] interface {
	Name() string
	Run(*S) error
}

Stage 描述一个可按顺序执行的启动阶段。

Jump to

Keyboard shortcuts

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