package com.zanxiang.game.data.serve.task;

import com.zanxiang.game.data.serve.service.IGameMonitorAlarmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author tianhua
 * @version 1.0
 * @description: 游戏监控告警定时任务
 * @date 2023/12/13 19:08
 */
@Slf4j
@Component
@RefreshScope
public class GameMonitorAlarmTask {

    @Autowired
    private IGameMonitorAlarmService gameMonitorAlarmService;

    @Value("${sys-config.task_is_run}")
    private boolean run;

    /**
     * 任务每5分钟运行一次
     */
    @Scheduled(cron = "0 0/5 * * * ? ")
    public void run() {
        if (!run) {
            return;
        }
        log.error("游戏监控告警定时任务开始.");
        try {
            gameMonitorAlarmService.sendMsgToUser();
        } catch (Exception e) {
            log.error("定时任务游戏监控告警出错", e);
        }
    }

}
