package checkCenter

import (
	mhayaFacade "github.com/mhaya/facade"
	rpcCenter "github.com/mhaya/game/game_cluster/internal/rpc/center"
	mhayaLogger "github.com/mhaya/logger"
	"time"
)

// Component 启动时,检查center节点是否存活
type Component struct {
	mhayaFacade.Component
}

func New() *Component {
	return &Component{}
}

func (c *Component) Name() string {
	return "run_check_component"
}

func (c *Component) OnAfterInit() {
	for {
		if rpcCenter.Ping(c.App()) {
			break
		}
		time.Sleep(2 * time.Second)
		mhayaLogger.Warn("center node connect fail. retrying in 2 seconds.")
	}
}
