Skip to content

Commit

Permalink
feat: add dfdaemon upload server healthy interface
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Mar 25, 2022
1 parent cfe3981 commit 279ade3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions client/daemon/upload/upload_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func WithLimiter(limiter *rate.Limiter) func(*uploadManager) {

func (um *uploadManager) initRouter() {
r := mux.NewRouter()
r.HandleFunc("/healthy", um.handleHealth).Methods("GET")
r.HandleFunc(PeerDownloadHTTPPathPrefix+"{taskPrefix:.*}/"+"{task:.*}", um.handleUpload).Queries("peerId", "{.*}").Methods("GET")
um.Server.Handler = r
}
Expand All @@ -85,6 +86,15 @@ func (um *uploadManager) Stop() error {
return um.Server.Shutdown(context.Background())
}

// handleHealth uses to check server health.
func (um *uploadManager) handleHealth(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Header().Set(headers.ContentType, "application/json")
if _, err := w.Write([]byte("OK")); err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
}

// handleUpload uses to upload a task file when other peers download from it.
func (um *uploadManager) handleUpload(w http.ResponseWriter, r *http.Request) {
var (
Expand Down
2 changes: 1 addition & 1 deletion manager/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func Init(cfg *config.Config, logDir string, service service.Service, enforcer *
pv1.GET(":id", h.GetV1Preheat)

// Health Check
r.GET("/healthy/*action", h.GetHealth)
r.GET("/healthy", h.GetHealth)

// Swagger
apiSeagger := ginSwagger.URL("/swagger/doc.json")
Expand Down

0 comments on commit 279ade3

Please sign in to comment.