faas/gateway/handlers/asyncreport.go
Alex Ellis bd146f526c Sync async_nats work with master
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
2017-08-29 19:40:08 +01:00

24 lines
583 B
Go

package handlers
import (
"encoding/json"
"io/ioutil"
"net/http"
"github.com/alexellis/faas/gateway/metrics"
"github.com/alexellis/faas/gateway/requests"
)
// MakeAsyncReport makes a handler for asynchronous invocations to report back into.
func MakeAsyncReport(metrics metrics.MetricOptions) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
report := requests.AsyncReport{}
bytesOut, _ := ioutil.ReadAll(r.Body)
json.Unmarshal(bytesOut, &report)
trackInvocation(report.FunctionName, metrics, report.StatusCode)
}
}