-
Notifications
You must be signed in to change notification settings - Fork 90
/
status.go
65 lines (54 loc) · 1.81 KB
/
status.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package handlers
import (
"fmt"
"net/http"
"strconv"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/store"
)
type GetUpdateDownloadStatusResponse struct {
CurrentMessage string `json:"currentMessage"`
Status string `json:"status"`
}
func (h *Handler) GetUpdateDownloadStatus(w http.ResponseWriter, r *http.Request) {
status, message, err := store.GetStore().GetTaskStatus("update-download")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
logger.Error(err)
return
}
JSON(w, http.StatusOK, GetUpdateDownloadStatusResponse{
CurrentMessage: message,
Status: status,
})
}
type GetAppVersionDownloadStatusResponse struct {
CurrentMessage string `json:"currentMessage"`
Status string `json:"status"`
Error string `json:"error"`
}
func (h *Handler) GetAppVersionDownloadStatus(w http.ResponseWriter, r *http.Request) {
getAppVersionDownloadStatusResponse := GetAppVersionDownloadStatusResponse{}
sequence, err := strconv.Atoi(mux.Vars(r)["sequence"])
if err != nil {
errMsg := "failed to parse sequence number"
logger.Error(errors.Wrap(err, errMsg))
getAppVersionDownloadStatusResponse.Error = errMsg
w.WriteHeader(http.StatusBadRequest)
return
}
taskID := fmt.Sprintf("update-download.%d", sequence)
status, message, err := store.GetStore().GetTaskStatus(taskID)
if err != nil {
errMsg := fmt.Sprintf("failed to get %s task status", taskID)
logger.Error(errors.Wrap(err, errMsg))
getAppVersionDownloadStatusResponse.Error = errMsg
w.WriteHeader(http.StatusInternalServerError)
return
}
getAppVersionDownloadStatusResponse.CurrentMessage = message
getAppVersionDownloadStatusResponse.Status = status
JSON(w, http.StatusOK, getAppVersionDownloadStatusResponse)
}