package com.jiayue.ipfcst.client.Schedule;

import cn.hutool.http.HttpUtil;
import com.jiayue.ipfcst.client.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


/**
 * 默认执行的定时任务
 * 1.与云预测的心跳
 *
 */
@Component
@Configuration
@EnableScheduling
@Slf4j
@EnableAsync
public class ConfigTask {
	/**
	 * 与云预测保持心跳通信
	 * 1.获取云上的实时配置信息
	 * 2.向云平台发送在线通知
	 * 每5分钟通知一次
	 */
	@Async
	@Scheduled(initialDelay =30 * 1000, fixedRateString = "300000")
	void heartbeatCommunication(){
		log.info("开始执行定时任务：与云预测心跳通信并获取基本配置信息");
		try{
			Constant.cacheClientConfig = ClientFileUtils.syncClientConfig();
		}catch (Throwable e){
			log.error("与云预测服务心跳通信错误,请在首页检查云平台地址和测试网络连通性，请求云端错误信息：{}",e.getLocalizedMessage());
		}
		log.info("与云预测心跳通信任务结束");
	}
}
