package main

import (
	"fmt"
	"os"
	"os/signal"
	"syscall"

	"applet/app/cfg"
	"applet/app/db"
	"applet/app/task"
	"applet/app/utils/logx"
)

func init() {
	cfg.InitTaskCfg()
	cfg.InitLog()
	cfg.InitCache()
	cfg.InitMq()
	baseDb := *cfg.DB
	baseDb.Path = fmt.Sprintf(cfg.DB.Path, cfg.DB.Name)
	if err := db.InitDB(&baseDb); err != nil {
		panic(err)
	}
	if err := db.InitZhimengDB(cfg.ZhimengDB); err != nil {
		panic(err)
	}
	//utils.CurlDebug = true
	cfg.InitMemCache()
}

func main() {
	go func() {
		task.Init()
		task.Run()
	}()
	// graceful shutdown
	quit := make(chan os.Signal)
	signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
	<-quit
	_ = logx.Info("Server exiting...")
}
