Run tests and script in parralel to prevent timing out

This commit is contained in:
Akbar Rahman 2021-08-04 22:17:43 +01:00
parent 081aaee9c7
commit a3ded5a052

17
main.go
View File

@ -75,6 +75,8 @@ func webhookHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
// run test and script in parralel to prevent timing out
go func(){
// Run tests, immediately stop if one fails // Run tests, immediately stop if one fails
for _, test := range service.Tests { for _, test := range service.Tests {
if _, err := test.Execute(payload); err != nil { if _, err := test.Execute(payload); err != nil {
@ -84,14 +86,15 @@ func webhookHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
} }
stdout, err := service.Script.Execute(payload)
if stdout, err := service.Script.Execute(payload); err != nil { fmt.Println(stdout)
writeResponse(w, 500, err.Error()) if err != nil {
return fmt.Println(err.Error())
} else {
writeResponse(w, 200, string(stdout))
return
} }
}()
writeResponse(w, 200, "OK")
return
} }
func writeResponse(w http.ResponseWriter, responseCode int, responseString string) { func writeResponse(w http.ResponseWriter, responseCode int, responseString string) {