package main

import (
	"fmt"
	"os"

	"ems.agt/lib/dborm"
	"ems.agt/lib/global"
	"ems.agt/lib/log"
)

func main() {

	log.InitLogger(yamlConfig.Logger.File, yamlConfig.Logger.Duration, yamlConfig.Logger.Count, "omc:crontask", GetLogLevel())
	fmt.Printf("OMC crontask version: %s\n", global.Version)
	log.Infof("========================= OMC crontask startup =========================")
	log.Infof("OMC crontask version: %s %s %s", global.Version, global.BuildTime, global.GoVer)

	err := dborm.InitDbClient(yamlConfig.Database.Type, yamlConfig.Database.User, yamlConfig.Database.Password,
		yamlConfig.Database.Host, yamlConfig.Database.Port, yamlConfig.Database.Name)
	if err != nil {
		fmt.Println("dborm.initDbClient err:", err)
		os.Exit(1)
	}

	err = initDbClient()
	if err != nil {
		fmt.Println("initDBClient error:", err)
		os.Exit(1)
	}

	ReadTasksYaml(yamlConfig.Tasks.File)

	//go ReloadRoutine()

	go initCronTasks()

	go initCronTabs()

	select {}
}
