1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Graceful: Cancel Process on monitor pages & HammerTime (#9213)

* Graceful: Create callbacks to with contexts

* Graceful: Say when Gitea is completely finished

* Graceful: Git and Process within HammerTime

Force all git commands to terminate at HammerTime
Force all process commands to terminate at HammerTime
Move almost all git processes to run as git Commands

* Graceful: Always Hammer after Shutdown

* ProcessManager: Add cancel functionality

* Fix tests

* Make sure that process.Manager.Kill() cancels

* Make threadsafe access to Processes and remove own unused Kill

* Remove cmd from the process manager as it is no longer used

* the default context is the correct context

* get rid of double till
This commit is contained in:
zeripath
2019-11-30 08:40:22 -06:00
committed by Lauris BH
parent 8f8c250ddb
commit 60c5339042
21 changed files with 536 additions and 198 deletions

View File

@@ -8,6 +8,7 @@
package graceful
import (
"context"
"os"
"strconv"
"sync"
@@ -29,6 +30,7 @@ const (
)
type gracefulManager struct {
ctx context.Context
isChild bool
lock *sync.RWMutex
state state
@@ -40,10 +42,11 @@ type gracefulManager struct {
terminateWaitGroup sync.WaitGroup
}
func newGracefulManager() *gracefulManager {
func newGracefulManager(ctx context.Context) *gracefulManager {
manager := &gracefulManager{
isChild: false,
lock: &sync.RWMutex{},
ctx: ctx,
}
manager.createServerWaitGroup.Add(numberOfServersToCreate)
manager.Run()
@@ -89,23 +92,29 @@ func (g *gracefulManager) Execute(args []string, changes <-chan svc.ChangeReques
waitTime := 30 * time.Second
loop:
for change := range changes {
switch change.Cmd {
case svc.Interrogate:
status <- change.CurrentStatus
case svc.Stop, svc.Shutdown:
for {
select {
case <-g.ctx.Done():
g.doShutdown()
waitTime += setting.GracefulHammerTime
break loop
case hammerCode:
g.doShutdown()
g.doHammerTime(0 * time.Second)
break loop
default:
log.Debug("Unexpected control request: %v", change.Cmd)
case change := <-changes:
switch change.Cmd {
case svc.Interrogate:
status <- change.CurrentStatus
case svc.Stop, svc.Shutdown:
g.doShutdown()
waitTime += setting.GracefulHammerTime
break loop
case hammerCode:
g.doShutdown()
g.doHammerTime(0 * time.Second)
break loop
default:
log.Debug("Unexpected control request: %v", change.Cmd)
}
}
}
status <- svc.Status{
State: svc.StopPending,
WaitHint: uint32(waitTime / time.Millisecond),