package com.spring.domain.schedule.service;

import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.springframework.stereotype.Service;

import com.spring.common.error.BizBaseException;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class ScheduleControlService {

    private final Scheduler scheduler;

    public void pauseJob(String groupName, String jobName) {
        try {
            JobKey jobKey = new JobKey(jobName, groupName);
            scheduler.pauseJob(jobKey);
        } catch (SchedulerException e) {
            throw new BizBaseException();
        }
    }

    public void resumeJob(String groupName, String jobName) {
        try {
            JobKey jobKey = new JobKey(jobName, groupName);
            scheduler.resumeJob(jobKey);
        } catch (SchedulerException e) {
            throw new BizBaseException();
        }
    }

    public void triggerJob(String groupName, String jobName) {
        try {
            JobKey jobKey = new JobKey(jobName, groupName);
            scheduler.triggerJob(jobKey);
        } catch (SchedulerException e) {
            throw new BizBaseException();
        }
    }

}
