Observe + metrics
This commit is contained in:
29
main.go
29
main.go
@@ -1,23 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"oc-peer/infrastructure"
|
||||
_ "oc-peer/routers"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"cloud.o-forge.io/core/oc-lib/config"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
const appname = "oc-peer"
|
||||
|
||||
func main() {
|
||||
for _, info := range beego.BeeApp.Handlers.GetAllControllerInfo() {
|
||||
fmt.Println(info.GetPattern())
|
||||
}
|
||||
oclib.InitAPI(appname, map[string][]string{
|
||||
"/oc/decentralized/search/:search": {"GET"},
|
||||
"/oc/decentralized/observe": {"GET"},
|
||||
})
|
||||
go infrastructure.ListenNATS()
|
||||
beego.Run()
|
||||
// On startup: reset all ongoing observations in oc-discovery.
|
||||
// If oc-peer crashed while oc-discovery was still running, oc-discovery may
|
||||
// hold stale observe streams. Close-all clears them and enters drain mode.
|
||||
go infrastructure.EmitCloseAll("")
|
||||
|
||||
d := oclib.NewRequestAdmin(oclib.LibDataEnum(oclib.PEER), nil).LoadAll(false, 0, 100000)
|
||||
for _, dd := range d.Data {
|
||||
if b, err := json.Marshal(dd); err == nil {
|
||||
go infrastructure.EmitNATS("root", []string{}, tools.PropalgationMessage{
|
||||
DataType: tools.PEER.EnumIndex(),
|
||||
Action: tools.PB_CREATE,
|
||||
Payload: b,
|
||||
})
|
||||
}
|
||||
}
|
||||
// Retry observe for offline peers every minute.
|
||||
infrastructure.StartOfflineRetryLoop()
|
||||
if config.GetConfig().IsApi {
|
||||
beego.Run()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user