package com.sonic.frog.job;


import com.sonic.common.client.JobmanClient;
import com.sonic.common.utils.LogUtils;
import com.sonic.frog.service.AiUserHeartbeatRelationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

/**
 * 生成图片任务前端心跳过期数据扫描
 * @author mzc
 */
@Slf4j
@Component
public class Hours24NoChatSubtractHeartbeatValJob {

    @Autowired
    private JobmanClient jobmanClient;
    @Autowired
    private AiUserHeartbeatRelationService aiUserHeartbeatRelationService;

    /** 每10分钟执行一次 */
//    @Scheduled(cron = "0 0/30 * * * ? ")
    @Scheduled(cron = "0/30 * * * * ? ")
    public void hours24NoChatSubtractHeartbeatValSchedule() {
        // 锁 1 分钟过期
        jobmanClient.run("hours24NoChatSubtractHeartbeatValJob", TimeUnit.MINUTES.toSeconds(2), this::hours24NoChatSubtractHeartbeatValJob);
    }

    protected JobmanClient.JobResult hours24NoChatSubtractHeartbeatValJob(JobmanClient.JobContext jobContext) {
        try {
            LogUtils.setTraceId();
            log.info("===> hours24NoChatSubtractHeartbeatValJob start !!!");
            aiUserHeartbeatRelationService.hours24NoChatSubtractHeartbeatValJob();
            log.info("===> hours24NoChatSubtractHeartbeatValJob count : {} end !!!", 0);
            return JobmanClient.JobResult.success(0);
        } finally {
            LogUtils.removeTraceId();
        }
    }
}