package com.skr.mdm.quartz.trigger;

import com.skr.mdm.util.DateUtil;
import com.skr.mdm.util.JobUtil;
import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.TriggerBuilder;

import java.util.Date;

/**
 * @author nfq
 * @date 2022-11-01 18:00
 */
public class CronTriggerHandler {

    public static CronTrigger build(JobDetail jobDetail, String triggerKey, Date executeTime) {
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail)
                .withIdentity(JobUtil.getTriggerKey(triggerKey))
                .withSchedule(CronScheduleBuilder.cronSchedule(DateUtil.getCron(executeTime))
                        .withMisfireHandlingInstructionDoNothing())
                .build();
    }
}
