grace

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SoftLimit = 5 * time.Second  // cancel requests context
	HardLimit = 10 * time.Second // immediately stop server
)

Variables

This section is empty.

Functions

func Run

func Run(processes ...Process)

Run will start Process's in parallel and take care about graceful shutdown. If one process stops every other will stop too

Types

type Process

type Process interface {
	// Name will be logged on start
	Name() string
	// Run blocks until application stops
	Run() error
	// Shutdown will gracefully shutdown process
	Shutdown() error
}

Process is a simple interface for long running processes

func GRPC

func GRPC(srv *grpc.Server, addr string) Process

GRPC adapts grpc.Server to the Process interface, accepts port in the ":8080" form. Cancel all requests (unary and stream) context after 5s soft limit, and waits rpcs

func GRPCUI

func GRPCUI(addr, appServerAddr string) Process

GRPCUI will create http server that serve front-end for grpc requests to application (analogue swagger)

Read more: https://github.com/fullstorydev/grpcui

func HTTP

func HTTP(srv *http.Server, addr string, hijackedWG ...*sync.WaitGroup) Process

HTTP adapts http.Server to the Process interface, accepts port in the ":8080" form.

All requests context will be done after 5s calling shutdown method. hijackedWG is an optional waitgroup to wait for a graceful shutdown of websockets or server-sent events. HTTP server doesn't care about them itself

func Prometheus

func Prometheus(addr string) Process

Prometheus add prometheus http server, accepts port in the ":8080" form.

It design to used with "github.com/prometheus/client_golang/prometheus/promauto" You can create promauto metrics and this handler will catch them automatically.

You can curl text file with the all metrics on host "addr" and "/" path (e.g. curl localhost:9090)

Jump to

Keyboard shortcuts

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