mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-22 18:01:02 +00:00
fixed some race conditions and cpu locking
This commit is contained in:
parent
80d8d10c15
commit
091f0e9918
5 changed files with 17 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -9,6 +9,7 @@ drone.sublime-workspace
|
|||
*.deb.*
|
||||
*.rpm
|
||||
*.out
|
||||
*.prof
|
||||
*.rice-box.go
|
||||
*.db
|
||||
*.txt
|
||||
|
|
2
drone.go
2
drone.go
|
@ -17,6 +17,8 @@ import (
|
|||
eventbus "github.com/drone/drone/eventbus/builtin"
|
||||
queue "github.com/drone/drone/queue/builtin"
|
||||
runner "github.com/drone/drone/runner/builtin"
|
||||
|
||||
_ "net/http/pprof"
|
||||
)
|
||||
|
||||
var conf = flag.String("config", "drone.toml", "")
|
||||
|
|
|
@ -177,6 +177,8 @@ func RunBuild(c *gin.Context) {
|
|||
raw = []byte(inject.InjectSafe(string(raw), params))
|
||||
}
|
||||
|
||||
c.JSON(202, build)
|
||||
|
||||
queue_.Publish(&queue.Work{
|
||||
User: user,
|
||||
Repo: repo,
|
||||
|
@ -185,8 +187,6 @@ func RunBuild(c *gin.Context) {
|
|||
Netrc: netrc,
|
||||
Yaml: raw,
|
||||
})
|
||||
|
||||
c.JSON(202, build)
|
||||
}
|
||||
|
||||
// KillBuild accepts a request to kill a running build.
|
||||
|
|
|
@ -145,6 +145,8 @@ func PostHook(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
c.JSON(200, build)
|
||||
|
||||
queue_.Publish(&queue.Work{
|
||||
User: user,
|
||||
Repo: repo,
|
||||
|
@ -153,6 +155,4 @@ func PostHook(c *gin.Context) {
|
|||
Netrc: netrc,
|
||||
Yaml: raw,
|
||||
})
|
||||
|
||||
c.JSON(200, build)
|
||||
}
|
||||
|
|
13
server/ws.go
13
server/ws.go
|
@ -46,23 +46,29 @@ func GetRepoEvents(c *gin.Context) {
|
|||
}
|
||||
|
||||
ticker := time.NewTicker(pingPeriod)
|
||||
eventc := make(chan *eventbus.Event, 1)
|
||||
eventc := make(chan *eventbus.Event)
|
||||
bus.Subscribe(eventc)
|
||||
defer func() {
|
||||
bus.Unsubscribe(eventc)
|
||||
ticker.Stop()
|
||||
ws.Close()
|
||||
close(eventc)
|
||||
log.Debugf("closed websocket")
|
||||
log.Infof("closed websocket")
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-c.Writer.CloseNotify():
|
||||
ws.Close()
|
||||
return
|
||||
case event := <-eventc:
|
||||
if event != nil && event.Kind == eventbus.EventRepo && event.Name == repo.FullName {
|
||||
if event == nil {
|
||||
log.Infof("closed websocket")
|
||||
ws.Close()
|
||||
return
|
||||
}
|
||||
if event.Kind == eventbus.EventRepo && event.Name == repo.FullName {
|
||||
ws.WriteMessage(websocket.TextMessage, event.Msg)
|
||||
break
|
||||
}
|
||||
|
@ -70,6 +76,7 @@ func GetRepoEvents(c *gin.Context) {
|
|||
ws.SetWriteDeadline(time.Now().Add(writeWait))
|
||||
err := ws.WriteMessage(websocket.PingMessage, []byte{})
|
||||
if err != nil {
|
||||
log.Infof("closed websocket")
|
||||
ws.Close()
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue