shutdown

package
v1.0.1327 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 11

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")

	registryLock.Lock()
	tasks := shutdownTasks
	shutdownTasks = nil
	registryLock.Unlock()

	sort.SliceStable(tasks, func(i, j int) bool {
		return tasks[i].Priority < tasks[j].Priority
	})

	for _, task := range tasks {
		if task.Hook == nil {
			continue
		}
		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 added in v1.0.730

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 added in v1.0.730

type ShutdownTask struct {
	Hook     shutdownHook
	Label    string
	Priority int
}

Jump to

Keyboard shortcuts

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