package main

import (
	"../gameapi"
	"../log"
	"../nt"
	"../utils"
	"./executor"
	"encoding/json"
	"fmt"
	"go.uber.org/zap"
)

func init_by_conf(cf string) {
	var err error
	err = nt.InstInit("taskpool", VERSION, cf)
	utils.ErrPanic(err)

	// 注册自己
	rawjson, err := json.Marshal(nt.InstConf)
	utils.ErrPanic(err)

	path_of_self := nt.ZkP.Misc + "/" + nt.InstName
	err = nt.Zk.CreateEmpNode(path_of_self, rawjson)
	utils.ErrPanic(err)
	//// 监视自己
	//nt.RegisterNodeCallback(path_of_self, on_notify_node_event)
	// 监视钱包
	nt.RegisterNodeCallback(nt.ZkP.Wallet, on_notify_node_event)

	err = nt.DynConf.MonitorKv()
	utils.ErrPanic(err)

	err = nt.DynConf.MonitorLobbies()
	utils.ErrPanic(err)

	err = nt.DynConf.MonitorWallet()
	utils.ErrPanic(err)

	gameapi.InitGameAPIConf()

	fmt.Printf("%v Boot At %s all ok.\n", nt.InstName, nt.BootTime.Format("2006-01-02 15:04:05"))
}

func init_pool() {
	executor.SetMode(nt.InstConf.Mode)

	loader := executor.NewPoolRedisLoader(nt.Rdb)
	TaskPool = executor.NewPool(ChQuit, loader)

	err := loader.LoadTo(TaskPool)
	if err != nil {
		log.Warn("init_pool", zap.Error(err))
	}

	TaskPool.Start()
}