forked from openfaas/faas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asyncreport.go
33 lines (25 loc) · 908 Bytes
/
asyncreport.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// 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/ngduchai/faas/gateway/metrics"
"github.com/ngduchai/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)
}
}