diff options
author | zeripath <art27@cantab.net> | 2019-11-30 08:40:22 -0600 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-11-30 16:40:22 +0200 |
commit | 60c5339042a605076482320313e8f9498dd72af9 (patch) | |
tree | bef1e4a0fb9565140fbf142f13d3b7e5f334031d /modules/graceful/manager_windows.go | |
parent | 8f8c250ddbe8dfe785340cb45cbae71c4833acf3 (diff) | |
download | gitea-60c5339042a605076482320313e8f9498dd72af9.tar.gz gitea-60c5339042a605076482320313e8f9498dd72af9.zip |
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
Diffstat (limited to 'modules/graceful/manager_windows.go')
-rw-r--r-- | modules/graceful/manager_windows.go | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/modules/graceful/manager_windows.go b/modules/graceful/manager_windows.go index 925b1fc560..dd48a8d74c 100644 --- a/modules/graceful/manager_windows.go +++ b/modules/graceful/manager_windows.go @@ -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), |