2019-11-30 23:40:22 +09:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-28 03:20:29 +09:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-11-30 23:40:22 +09:00
|
|
|
|
|
|
|
package graceful
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
2023-11-15 23:02:46 +09:00
|
|
|
// Shutdown procedure:
|
|
|
|
// * cancel ShutdownContext: the registered context consumers have time to do their cleanup (they could use the hammer context)
|
|
|
|
// * cancel HammerContext: the all context consumers have limited time to do their cleanup (wait for a few seconds)
|
|
|
|
// * cancel TerminateContext: the registered context consumers have time to do their cleanup (but they shouldn't use shutdown/hammer context anymore)
|
|
|
|
// * cancel manager context
|
|
|
|
// If the shutdown is triggered again during the shutdown procedure, the hammer context will be canceled immediately to force to shut down.
|
|
|
|
|
2019-11-30 23:40:22 +09:00
|
|
|
// ShutdownContext returns a context.Context that is Done at shutdown
|
|
|
|
// Callers using this context should ensure that they are registered as a running server
|
|
|
|
// in order that they are waited for.
|
2019-12-15 18:51:28 +09:00
|
|
|
func (g *Manager) ShutdownContext() context.Context {
|
2021-05-15 23:22:26 +09:00
|
|
|
return g.shutdownCtx
|
2019-11-30 23:40:22 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// HammerContext returns a context.Context that is Done at hammer
|
|
|
|
// Callers using this context should ensure that they are registered as a running server
|
|
|
|
// in order that they are waited for.
|
2019-12-15 18:51:28 +09:00
|
|
|
func (g *Manager) HammerContext() context.Context {
|
2021-05-15 23:22:26 +09:00
|
|
|
return g.hammerCtx
|
2019-11-30 23:40:22 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// TerminateContext returns a context.Context that is Done at terminate
|
|
|
|
// Callers using this context should ensure that they are registered as a terminating server
|
|
|
|
// in order that they are waited for.
|
2019-12-15 18:51:28 +09:00
|
|
|
func (g *Manager) TerminateContext() context.Context {
|
2021-05-15 23:22:26 +09:00
|
|
|
return g.terminateCtx
|
2019-11-30 23:40:22 +09:00
|
|
|
}
|