fix: execute script in background to not block response
This commit is contained in:
parent
2ff3299ad7
commit
b11c8cbcbf
18
main.go
18
main.go
|
@ -40,7 +40,6 @@ func handlePayload(secret string, scripts map[string]config.ConfigScript) func(w
|
|||
defer r.Body.Close()
|
||||
|
||||
authHeader := r.Header.Get("Authorization")
|
||||
log.Println("authHeader", authHeader)
|
||||
if authHeader != secret {
|
||||
http.Error(w, "Signatures didn't match", http.StatusUnauthorized)
|
||||
return
|
||||
|
@ -57,22 +56,17 @@ func handlePayload(secret string, scripts map[string]config.ConfigScript) func(w
|
|||
http.Error(w, "not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("body", body)
|
||||
// Parse the JSON payload
|
||||
var payload interface{}
|
||||
err = json.Unmarshal(body, &payload)
|
||||
if err != nil {
|
||||
if err = json.Unmarshal(body, &payload); err != nil {
|
||||
http.Error(w, "Failed to parse JSON payload", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: Do something with the payload
|
||||
fmt.Fprintf(w, "I got some JSON: %v", payload)
|
||||
|
||||
if err := execute(scr.BinaryPath, scr.ScriptPath); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
go func() {
|
||||
if err := execute(scr.BinaryPath, scr.ScriptPath); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue