Skip to content

Commit

Permalink
[Tenscan] Endpoint for health check (#1718)
Browse files Browse the repository at this point in the history
* wip: add an endpoint for health check

* feat: add endpoint for health check

* Refactor health status method names

* Refactor health check function calls
  • Loading branch information
Jennievon authored Jan 8, 2024
1 parent b6dada7 commit f77ac97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/tenscan/backend/obscuroscan_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func (b *Backend) GetLatestBatch() (*common.BatchHeader, error) {
return b.obsClient.BatchHeaderByNumber(nil)
}

func (b *Backend) GetTenNodeHealthStatus() (bool, error) {
return b.obsClient.Health()
}

func (b *Backend) GetLatestRollup() (*common.RollupHeader, error) {
return &common.RollupHeader{}, nil
}
Expand Down
8 changes: 8 additions & 0 deletions tools/tenscan/backend/webserver/webserver_routes_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ func routeItems(r *gin.Engine, server *WebServer) {
r.GET("/items/batches/", server.getBatchListing)
r.GET("/items/blocks/", server.getBlockListing)
r.GET("/info/obscuro/", server.getConfig)
r.POST("/info/health/", server.getHealthStatus)
}

func (w *WebServer) getHealthStatus(c *gin.Context) {
healthStatus, err := w.backend.GetTenNodeHealthStatus()

// TODO: error handling, since this does not easily tell connection errors from health errors
c.JSON(http.StatusOK, gin.H{"result": healthStatus, "errors": fmt.Sprintf("%s", err)})
}

func (w *WebServer) getLatestBatch(c *gin.Context) {
Expand Down

0 comments on commit f77ac97

Please sign in to comment.