gitech
1// Copyright 2019 The Gitea Authors. All rights reserved.
2// SPDX-License-Identifier: MIT
3
4package graceful
5
6import (
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.
20func (g *Manager) ShutdownContext() context.Context {
21return 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.
27func (g *Manager) HammerContext() context.Context {
28return 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.
34func (g *Manager) TerminateContext() context.Context {
35return g.terminateCtx
36}
37