package net.educoder.ecsonar.task;

import net.educoder.ecsonar.services.DbOperateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.Callable;

/**
 * @Author: youys
 * @Date: 2023/8/31
 * @Description: 毕业设计 查询分析结果
 */
public class GraduationProjectQueryResultRunnable implements Callable<String> {

    private static final Logger LOGGER = LoggerFactory.getLogger(GraduationProjectQueryResultRunnable.class);

    private String projectName;
    private String detailId;
    private DbOperateService dbOperateService;

    public GraduationProjectQueryResultRunnable(String projectName, String detailId, DbOperateService dbOperateService) {
        this.projectName = projectName;
        this.detailId = detailId;
        this.dbOperateService = dbOperateService;
    }


    @Override
    public String call() throws Exception {
        int count = 0;
        String status;
        while ((status = dbOperateService.queryCeActivityStatus(projectName)) == null && count++ <= 60) {
            LOGGER.info("detailId:[{}],sonar还未执行完,次数:{}", detailId, count);
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
            }
        }
        // 查询
        LOGGER.info("detailId:[{}], 查询sonar执行状态[{}]", detailId, status);
        return status;
    }
}
