graceful

package
v0.0.0-...-290478e Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package graceful contains tools for graceful shutdown. GS refers to the process of shutting down a system in a controlled manner, allowing it to complete ongoing tasks, release resources, and perform necessary cleanup operations before terminating. This ensures that the system stops functioning without causing data loss, corruption, or other issues.

Index

Constants

This section is empty.

Variables

DefaultProcess is a process instance with some sane defaults.

Functions

func AddService

func AddService(ctx context.Context, s Service)

func AddStarter

func AddStarter(ctx context.Context, fn func(ctx context.Context) error)

func AddStopper

func AddStopper(fn func())

func NewSigChan

func NewSigChan(signals ...os.Signal) chan os.Signal

NewSigChan creates a new signal channel.

func ShutdownNow

func ShutdownNow()

func WaitForShutdown

func WaitForShutdown()

Types

type Process

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

Process represents "virtual" process that contains routines that can be started and stopped Note that ANY failure in starting a service will cause the process to shutdown

func New

func New(timeout time.Duration, logger zerolog.Logger, stop <-chan os.Signal) *Process

New Process constructor.

func (*Process) AddService

func (p *Process) AddService(ctx context.Context, s Service)

AddService adds Service to the process.

func (*Process) AddStarter

func (p *Process) AddStarter(ctx context.Context, fn func(ctx context.Context) error)

AddStarter runs a function that starts something. This is a blocking call for blocking .Start() services

func (*Process) AddStopper

func (p *Process) AddStopper(fn func())

AddStopper adds a function will be executed during shutdown.

func (*Process) ShutdownNow

func (p *Process) ShutdownNow()

ShutdownNow invokes shutdown of all services.

func (*Process) WaitForShutdown

func (p *Process) WaitForShutdown()

WaitForShutdown blocks current routine until a shutdown signal is received

type Service

type Service interface {
	Start(ctx context.Context) error
	Stop()
}

Service represents abstract service.

Jump to

Keyboard shortcuts

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