Fixes #1: Add a mutex to prevent multiple builds

This commit is contained in:
Chris Sexton 2015-04-16 21:48:03 -04:00
parent ef78cc448d
commit ddab63e384
1 changed files with 5 additions and 1 deletions

View File

@ -15,6 +15,7 @@ import (
"os"
"os/exec"
"path/filepath"
"sync"
"time"
"github.com/gorilla/mux"
@ -27,6 +28,7 @@ var (
secret = flag.String("secret", "12345", "Secret to authorize builds")
projects map[string]*project
buildMutex sync.Mutex
)
type project struct {
@ -38,6 +40,7 @@ type project struct {
}
func runBuild(name string) {
buildMutex.Lock()
steps := fmt.Sprintf("mkdir -p %s; cd %s; %s",
name, name, projects[name].Before)
script := bytes.NewBufferString(steps)
@ -58,6 +61,7 @@ func runBuild(name string) {
if err == nil {
runPostBuild(name)
}
buildMutex.Unlock()
}
func runPostBuild(name string) {