diff --git a/.gitignore b/.gitignore index df07484a..be342d69 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ drone.sublime-workspace *.deb.* *.rpm *.out +*.prof *.rice-box.go *.db *.txt diff --git a/drone.go b/drone.go index 8274f891..9972d454 100644 --- a/drone.go +++ b/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", "") diff --git a/server/builds.go b/server/builds.go index 6c6213db..b6d41998 100644 --- a/server/builds.go +++ b/server/builds.go @@ -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. diff --git a/server/hooks.go b/server/hooks.go index d7af6de9..d95a0c95 100644 --- a/server/hooks.go +++ b/server/hooks.go @@ -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) } diff --git a/server/ws.go b/server/ws.go index efd0d233..be93d013 100644 --- a/server/ws.go +++ b/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 }