code.gitea.io/gitea@v1.22.3/modules/graceful/context.go (about) 1 // Copyright 2019 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package graceful 5 6 import ( 7 "context" 8 ) 9 10 // Shutdown procedure: 11 // * cancel ShutdownContext: the registered context consumers have time to do their cleanup (they could use the hammer context) 12 // * cancel HammerContext: the all context consumers have limited time to do their cleanup (wait for a few seconds) 13 // * cancel TerminateContext: the registered context consumers have time to do their cleanup (but they shouldn't use shutdown/hammer context anymore) 14 // * cancel manager context 15 // If the shutdown is triggered again during the shutdown procedure, the hammer context will be canceled immediately to force to shut down. 16 17 // ShutdownContext returns a context.Context that is Done at shutdown 18 // Callers using this context should ensure that they are registered as a running server 19 // in order that they are waited for. 20 func (g *Manager) ShutdownContext() context.Context { 21 return g.shutdownCtx 22 } 23 24 // HammerContext returns a context.Context that is Done at hammer 25 // Callers using this context should ensure that they are registered as a running server 26 // in order that they are waited for. 27 func (g *Manager) HammerContext() context.Context { 28 return g.hammerCtx 29 } 30 31 // TerminateContext returns a context.Context that is Done at terminate 32 // Callers using this context should ensure that they are registered as a terminating server 33 // in order that they are waited for. 34 func (g *Manager) TerminateContext() context.Context { 35 return g.terminateCtx 36 }