/*

 Copyright (c) [2023] [pcm]
 [pcm-coordinator] is licensed under Mulan PSL v2.
 You can use this software according to the terms and conditions of the Mulan PSL v2.
 You may obtain a copy of Mulan PSL v2 at:
          http://license.coscl.org.cn/MulanPSL2
 THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 See the Mulan PSL v2 for more details.

*/

package cron

import (
	"github.com/zeromicro/go-zero/core/logx"
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/utils/stat"
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/utils/status"
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
)

func AddCronGroup(svc *svc.ServiceContext) {

	svc.Cron.AddFunc("*/5  *  *  *  *  ?", func() {
		list, err := GetTaskList(svc)
		if err != nil {
			logx.Errorf(err.Error())
			return
		}
		status.UpdateTaskStatus(svc, list)
		status.UpdateAiTaskStatus(svc, list)
	})

	svc.Cron.AddFunc("*/5  *  *  *  *  ?", func() {
		UpdateAiAdapterMaps(svc)
	})

	svc.Cron.AddFunc("30  *  *  *  *  ?", func() {
		adapterList, err := svc.Scheduler.AiStorages.GetAdaptersByType("1")
		if err != nil {
			logx.Errorf(err.Error())
			return
		}
		stat.UpdateClusterResources(svc, adapterList)
	})

	svc.Cron.AddFunc("@hourly", func() {
		status.UpdateAutoStoppedInstance(svc)
	})
}
