Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3a7e682
Move process to create contexts
zeripath Sep 18, 2021
47bda44
display children processes
zeripath Sep 18, 2021
cd16cbb
Make requests a process
zeripath Sep 18, 2021
12039b9
Add context to repo and add ctx to OpenRepository
zeripath Sep 18, 2021
d2b01e4
minor comments
zeripath Sep 22, 2021
659fcf6
Merge remote-tracking branch 'origin/main' into request-as-process
zeripath Sep 23, 2021
9598eca
fix lint and children lock
zeripath Sep 23, 2021
3344e26
Merge remote-tracking branch 'origin/main' into request-as-process
zeripath Oct 10, 2021
7cf7749
separate remove and cancel functions
zeripath Oct 10, 2021
a8e228e
associate repo functions with the repo context
zeripath Oct 10, 2021
08b77d1
fix lint
zeripath Oct 13, 2021
47b0614
Merge remote-tracking branch 'origin/main' into request-as-process
zeripath Oct 13, 2021
518b79e
Merge remote-tracking branch 'origin/main' into request-as-process
zeripath Oct 15, 2021
9bb820b
Simplify PID to strings using the time of start plus/minus a counter
zeripath Oct 15, 2021
9895680
extract process out of manager.go
zeripath Oct 15, 2021
afc5b41
fix test
zeripath Oct 15, 2021
7446c87
Merge remote-tracking branch 'origin/main' into request-as-process
zeripath Oct 15, 2021
86ab980
Merge branch 'main' into request-as-process
zeripath Oct 17, 2021
4ce4614
Make the Mirror Queue a queue (#17326)
zeripath Oct 17, 2021
633b041
make mirroring a process
zeripath Oct 17, 2021
377a384
Ensure that mirrors are al within the same context
zeripath Oct 17, 2021
32c58ee
Merge remote-tracking branch 'origin/main' into request-as-process
zeripath Oct 17, 2021
71dec99
add clarity to the difference between cancel and remove
zeripath Oct 19, 2021
9e95fdb
add explanatory notes for remove and close
zeripath Oct 19, 2021
3010f59
Merge remote-tracking branch 'origin/main' into request-as-process
zeripath Oct 19, 2021
9cc97d0
explicitly name the arguments in the blame reader
zeripath Oct 19, 2021
e4aebfb
Change remove to finished
zeripath Oct 20, 2021
217fbf7
update blame documentation
zeripath Oct 20, 2021
6b6ac80
as per review
zeripath Oct 20, 2021
0fcbc38
Merge remote-tracking branch 'origin/main' into request-as-process
zeripath Oct 27, 2021
e06216b
Close the cat-file batch and checks after the context cancellation
zeripath Oct 27, 2021
2062e43
Merge remote-tracking branch 'origin/main' into request-as-process
zeripath Oct 28, 2021
46c2b7a
Merge branch 'main' into request-as-process
zeripath Nov 1, 2021
37bfa14
Merge branch 'main' into request-as-process
zeripath Nov 5, 2021
ad2e278
Merge remote-tracking branch 'origin/main' into request-as-process
zeripath Nov 16, 2021
6062b04
Merge remote-tracking branch 'origin/main' into request-as-process
zeripath Nov 20, 2021
59dc919
Merge remote-tracking branch 'origin/main' into request-as-process
zeripath Nov 26, 2021
347e6a8
Merge branch 'main' into request-as-process
lafriks Nov 28, 2021
fd86412
Merge branch 'main' into request-as-process
lunny Nov 28, 2021
0d1ae72
Merge remote-tracking branch 'origin/main' into request-as-process
zeripath Nov 28, 2021
1d565bb
Merge branch 'main' into request-as-process
zeripath Nov 29, 2021
bbe69c8
Merge branch 'main' into request-as-process
zeripath Nov 30, 2021
1203fa9
Ensure that http requests use the same context as the request
zeripath Nov 30, 2021
772d31d
use the repo context in the diff
zeripath Nov 30, 2021
37f0716
improve code documentation
zeripath Nov 30, 2021
ec6b663
use the gitrepo context
zeripath Nov 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
extract process out of manager.go
Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath committed Oct 15, 2021
commit 9895680f4a8ff01f53e1431aedf793298118d004
50 changes: 12 additions & 38 deletions modules/process/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,6 @@ var (
// IDType is a pid type
type IDType string

// Process represents a working process inheriting from Gitea.
type Process struct {
PID IDType // Process ID, not system one.
ParentPID IDType
children []*Process
Description string
Start time.Time
Cancel context.CancelFunc
}

// Children gets the children of the process
func (p *Process) Children() []*Process {
var children []*Process
pm := GetManager()
pm.mutex.Lock()
defer pm.mutex.Unlock()
children = make([]*Process, len(p.children))
copy(children, p.children)
return children
}

// Manager knows about all processes and counts PIDs.
type Manager struct {
mutex sync.Mutex
Expand All @@ -74,7 +53,7 @@ func GetManager() *Manager {
return manager
}

// AddContext create a new context and add it as a process. The CancelFunc must always be called even if the context is Done()
// AddContext create a new context and add it as a process. The remove CancelFunc must always be called even if the context is Done()
func (pm *Manager) AddContext(parent context.Context, description string) (ctx context.Context, cancel, remove context.CancelFunc) {
parentPID := GetParentPID(parent)

Expand All @@ -88,7 +67,7 @@ func (pm *Manager) AddContext(parent context.Context, description string) (ctx c
}, cancel, remove
}

// AddContextTimeout create a new context and add it as a process
// AddContextTimeout create a new context and add it as a process. The remove CancelFunc must always be called even if the context is Done()
func (pm *Manager) AddContextTimeout(parent context.Context, timeout time.Duration, description string) (ctx context.Context, cancel, remove context.CancelFunc) {
parentPID := GetParentPID(parent)

Expand Down Expand Up @@ -126,7 +105,7 @@ func (pm *Manager) Add(parentPID IDType, description string, cancel context.Canc
}

if parent != nil {
parent.children = append(parent.children, process)
parent.AddChild(process)
}
pm.processes[pid] = process
pm.mutex.Unlock()
Expand Down Expand Up @@ -160,22 +139,17 @@ func (pm *Manager) Remove(pid IDType) {

func (pm *Manager) remove(process *Process) {
pm.mutex.Lock()
defer pm.mutex.Unlock()
if p := pm.processes[process.PID]; p == process {
delete(pm.processes, process.PID)
for _, child := range process.children {
child.ParentPID = ""
}
parent := pm.processes[process.ParentPID]
if parent != nil {
for i, child := range parent.children {
if child == process {
parent.children = append(parent.children[:i], parent.children[i+1:]...)
return
}
}
}
}
parent := pm.processes[process.ParentPID]
pm.mutex.Unlock()

if parent == nil {
return
}

parent.RemoveChild(process)
}

// Cancel a process in the ProcessManager.
Expand All @@ -194,7 +168,7 @@ func (pm *Manager) Processes(onlyRoots bool) []*Process {
processes := make([]*Process, 0, len(pm.processes))
if onlyRoots {
for _, process := range pm.processes {
if process.ParentPID == "" {
if _, has := pm.processes[process.ParentPID]; !has {
processes = append(processes, process)
}
}
Expand Down
66 changes: 66 additions & 0 deletions modules/process/process.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package process

import (
"context"
"sync"
"time"
)

// Process represents a working process inheriting from Gitea.
type Process struct {
PID IDType // Process ID, not system one.
ParentPID IDType
Description string
Start time.Time
Cancel context.CancelFunc

lock sync.Mutex
children []*Process
}

// Children gets the children of the process
// Note: this function will behave nicely even if p is nil
func (p *Process) Children() (children []*Process) {
if p == nil {
return
}

p.lock.Lock()
defer p.lock.Unlock()
children = make([]*Process, len(p.children))
copy(children, p.children)
return children
}

// AddChild adds a child process
// Note: this function will behave nicely even if p is nil
func (p *Process) AddChild(child *Process) {
if p == nil {
return
}

p.lock.Lock()
defer p.lock.Unlock()
p.children = append(p.children, child)
}

// RemoveChild removes a child process
// Note: this function will behave nicely even if p is nil
func (p *Process) RemoveChild(process *Process) {
if p == nil {
return
}

p.lock.Lock()
defer p.lock.Unlock()
for i, child := range p.children {
if child == process {
p.children = append(p.children[:i], p.children[i+1:]...)
return
}
}
}