shutdown

package
v0.1.97 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	PriorityIngress  = 100
	PriorityJobs     = 500
	PriorityCritical = 1000
)

Some helper priority levels

Variables

View Source
var Shutdown = sync.OnceFunc(func() {
	logger.Infof("begin shutdown")

	for len(shutdownTaskRegistry) > 0 {
		_task := heap.Pop(&shutdownTaskRegistry)
		if _task == nil {
			break
		}

		task := _task.(ShutdownTask)
		logger.Infof("shutting down: %s", task.Label)

		s := time.Now()
		task.Hook()
		logger.Infof("shutdown %s completed in %v", task.Label, time.Since(s))
	}
})

Functions

func AddHook

func AddHook(fn shutdownHook)

Add a hook with the least priority. Least priority hooks are run first.

Prefer AddHookWithPriority()

func AddHookWithPriority

func AddHookWithPriority(label string, priority int, fn shutdownHook)

AddHookWithPriority adds a hook with a priority level.

Execution order goes from lowest to highest priority numbers.

func ShutdownAndExit

func ShutdownAndExit(code int, msg string)

func WaitForSignal

func WaitForSignal()

Types

type ShutdownTask

type ShutdownTask struct {
	Hook     shutdownHook
	Label    string
	Priority int
}

type ShutdownTasks

type ShutdownTasks []ShutdownTask

ShutdownTasks implements heap.Interface

func (ShutdownTasks) Len

func (st ShutdownTasks) Len() int

func (ShutdownTasks) Less

func (st ShutdownTasks) Less(i, j int) bool

func (*ShutdownTasks) Pop

func (st *ShutdownTasks) Pop() interface{}

func (*ShutdownTasks) Push

func (st *ShutdownTasks) Push(x interface{})

func (ShutdownTasks) Swap

func (st ShutdownTasks) Swap(i, j int)

Jump to

Keyboard shortcuts

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