Fixes #1: Add a mutex to prevent multiple builds
This commit is contained in:
parent
ef78cc448d
commit
ddab63e384
|
@ -15,6 +15,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
@ -26,7 +27,8 @@ var (
|
||||||
addr = flag.String("addr", ":3001", "Address to serve on")
|
addr = flag.String("addr", ":3001", "Address to serve on")
|
||||||
secret = flag.String("secret", "12345", "Secret to authorize builds")
|
secret = flag.String("secret", "12345", "Secret to authorize builds")
|
||||||
|
|
||||||
projects map[string]*project
|
projects map[string]*project
|
||||||
|
buildMutex sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
type project struct {
|
type project struct {
|
||||||
|
@ -38,6 +40,7 @@ type project struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runBuild(name string) {
|
func runBuild(name string) {
|
||||||
|
buildMutex.Lock()
|
||||||
steps := fmt.Sprintf("mkdir -p %s; cd %s; %s",
|
steps := fmt.Sprintf("mkdir -p %s; cd %s; %s",
|
||||||
name, name, projects[name].Before)
|
name, name, projects[name].Before)
|
||||||
script := bytes.NewBufferString(steps)
|
script := bytes.NewBufferString(steps)
|
||||||
|
@ -58,6 +61,7 @@ func runBuild(name string) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
runPostBuild(name)
|
runPostBuild(name)
|
||||||
}
|
}
|
||||||
|
buildMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func runPostBuild(name string) {
|
func runPostBuild(name string) {
|
||||||
|
|
Loading…
Reference in New Issue