Skip to content

Commit

Permalink
feat: add status route
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Jun 24, 2023
1 parent 765312d commit 75a5dae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ func main() {
go NewRouter().Run(`:8080`)

for _, chainID := range chains {
setStatusForChainID(chainID, "Loading")
wg.Add(1)
go SummonDaemonsw(chainID, &wg)
}
wg.Wait()
for _, chainID := range chains {
setStatusForChainID(chainID, "OK")
}

logs.Success(`Server ready on port 8080 !`)
// pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)

select {}

case ProcessPartnerFees:
Expand Down
9 changes: 9 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ func NewRouter() *gin.Engine {
{
// Get some information about the API
GET(router, `info/chains`, utils.GetSupportedChains)
GET(router, `:chainID/status`, func(ctx *gin.Context) {
chainID, ok := helpers.AssertChainID(ctx.Param("chainID"))
if !ok {
ctx.JSON(http.StatusBadRequest, gin.H{"error": "invalid chainID"})
return
}
ctx.JSON(http.StatusOK, getStatusForChainID(chainID))
})

}

// Meta API section
Expand Down
19 changes: 19 additions & 0 deletions cmd/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import "github.com/yearn/ydaemon/common/env"

var STATUS_FOR_CHAINID = map[uint64]string{}

func init() {
for _, chainID := range env.SUPPORTED_CHAIN_IDS {
setStatusForChainID(chainID, "Not Started")
}
}

func setStatusForChainID(chainID uint64, status string) {
STATUS_FOR_CHAINID[chainID] = status
}

func getStatusForChainID(chainID uint64) string {
return STATUS_FOR_CHAINID[chainID]
}

1 comment on commit 75a5dae

@vercel
Copy link

@vercel vercel bot commented on 75a5dae Jun 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ydaemon – ./docs

ydaemon.yearn.farm
ydaemon-git-main.yearn.farm

Please sign in to comment.