package cron

import (
	"gitee.ltd/lxh/logger/log"
	"github.com/go-co-op/gocron/v2"
	"github.com/spf13/cast"
	"os"
	"time"
	"wireguard-ui/cron/task"
)

func Task() {
	if !cast.ToBool(os.Getenv("ENABLED_CRON")) {
		return
	}
	sch, err := gocron.NewScheduler(gocron.WithLocation(time.Local))
	if err != nil {
		log.Errorf("初始化定时任务失败")
		return
	}

	_, _ = sch.NewJob(gocron.DurationJob(1*time.Minute), gocron.NewTask(task.NetworkClient().ClientOfflineNotify)) // 每分钟执行一次
	sch.Start()
}
