//go:build !local
// +build !local

package main

import (
	"fmt"
	"time"

	"github.com/beego/beego/v2/server/web"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/crontab"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/mqtt"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/task"

	_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
	_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg"
	_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
	_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
	_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego"
)

func main() {
	defer func() {
		if r := recover(); r != nil {
			log.Logger.Error(fmt.Sprintf("%v", r))
		}
	}()

	log.InitLogHook(constant.ENABLE_KAFKA_LOG, true)
	redis.InitRedis()
	log.Logger.Info("server start ....")
	log.Logger.Debug(fmt.Sprintf("ENABLE_KAFKA_LOG:%v", constant.ENABLE_KAFKA_LOG))
	if constant.MQTT_UP {
		go mqtt.Start(log.Logger)
	}
	go task.Run()
	cron := crontab.NewCrontabService(nil)
	cron.StartCrontabTask()
	defer cron.StopCrontabTask()
	time.Sleep(time.Second)
	log.Logger.Info("server start!")
	web.Run()
	log.Logger.Info("server stop!")
}