package cd.casic.ci.process.engine.scheduler.job;

import cd.casic.ci.process.engine.executor.PipelineExecutor;
import cd.casic.ci.process.enums.PiplineTriggerModeEnum;
import jakarta.annotation.Resource;
import org.joda.time.LocalDateTime;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 * @author HopeLi
 * @version v1.0
 * @ClassName PipelineTaskJob
 * @Date: 2025/5/27 17:28
 * @Description:
 */
public class PipelineSchedulingJob implements Job {
    public static final String JOB_PARAM_PIPELINE_ID = "pipelineId";

    @Resource
    private PipelineExecutor executor;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap dataMap = context.getMergedJobDataMap();
        String pipelineId = dataMap.getString(JOB_PARAM_PIPELINE_ID);

        if (pipelineId != null && executor != null) {
            executor.execute(pipelineId, PiplineTriggerModeEnum.TIMING,null);
            System.out.println("定时任务开始执行，当前执行时间为" + new LocalDateTime());
        }
    }
}
