Skip to content

maxim-kuderko/graceful-shutdown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simple implementation

  1. set envs

    HEALTH_PORT=<PORT> // i.e 9999
    GRACEFUL_SHUTDOWN_TIMEOUT=30 // in seconds
  2. in code

import  gs "github.com/maxim-kuderko/graceful-shutdown"

func main(){
	go func{
		...application code
    }()
    gs.WaitForGrace()	
}

optional: use the gs.ShuttingDownHook() to start closing any background operation

import  gs "github.com/maxim-kuderko/graceful-shutdown"

func main(){
	c := make(chan struct{}, 1)
	go processC(c)
	
	gs.ShuttingDownHook()
	close(c)
    gs.WaitForGrace()	
}

func processC(c <-chan struct{}){
	..background operation...
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages