package com.eactive.eai.rms.onl.common.service;

import com.eactive.eai.rms.onl.common.service.ums.UmsDispatchService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Admin Job Configuration
 * ----------------------
 * Job ID: UMSDISPATCHJOB
 * Description: UMS 메시지 발송
 * Class: com.eactive.eai.rms.onl.common.service.UmsDispatchJob
 */
// Cron Expression: */5 * * * * ?
@Slf4j
public class UmsDispatchJob implements Job {
	
	 private final UmsDispatchService umsDispatchService;
    	
    @Autowired
    public UmsDispatchJob(UmsDispatchService umsDispatchService) {
    	this.umsDispatchService = umsDispatchService;
    }
    
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        log.info("Starting Message Dispatch Job...");
        try {
            umsDispatchService.processMessages();
        } catch (Exception e) {
            log.error("Failed to process messages", e);            
            throw new JobExecutionException(e);
        }
    }
}
