mirror of
https://github.com/alvierahman90/gohookr.git
synced 2024-11-24 20:59:52 +00:00
Run tests and script in parralel to prevent timing out
This commit is contained in:
parent
081aaee9c7
commit
a3ded5a052
33
main.go
33
main.go
@ -75,23 +75,26 @@ func webhookHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run tests, immediately stop if one fails
|
// run test and script in parralel to prevent timing out
|
||||||
for _, test := range service.Tests {
|
go func(){
|
||||||
if _, err := test.Execute(payload); err != nil {
|
// Run tests, immediately stop if one fails
|
||||||
writeResponse(w, 409,
|
for _, test := range service.Tests {
|
||||||
fmt.Sprintf("Conflict: Test failed: %v", err.Error()),
|
if _, err := test.Execute(payload); err != nil {
|
||||||
)
|
writeResponse(w, 409,
|
||||||
return
|
fmt.Sprintf("Conflict: Test failed: %v", err.Error()),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
stdout, err := service.Script.Execute(payload)
|
||||||
|
fmt.Println(stdout)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if stdout, err := service.Script.Execute(payload); err != nil {
|
writeResponse(w, 200, "OK")
|
||||||
writeResponse(w, 500, err.Error())
|
return
|
||||||
return
|
|
||||||
} else {
|
|
||||||
writeResponse(w, 200, string(stdout))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeResponse(w http.ResponseWriter, responseCode int, responseString string) {
|
func writeResponse(w http.ResponseWriter, responseCode int, responseString string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user