mirror of
https://github.com/openfaas/faas.git
synced 2025-06-08 16:26:47 +00:00
- splits out notifiers and writes status for async handler Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
34 lines
908 B
Go
34 lines
908 B
Go
// Copyright (c) Alex Ellis 2017. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/openfaas/faas/gateway/metrics"
|
|
"github.com/openfaas/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)
|
|
|
|
var taken time.Duration
|
|
taken = time.Duration(report.TimeTaken)
|
|
trackTimeExact(taken, metrics, report.FunctionName)
|
|
|
|
w.WriteHeader(http.StatusAccepted)
|
|
}
|
|
}
|