package com.samsung.batch.excutor;

import com.samsung.approval.knox.KnoxApprovalSyncService;
import lombok.extern.log4j.Log4j2;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

@Component
@Log4j2
public class KnoxSyncBatchExecutor extends QuartzJobBean {

    @Value("${node-id}")
    private String nodeId;

    @Autowired
    private KnoxApprovalSyncService knoxApprovalSyncService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) {
        JobDetail jobDetail = jobExecutionContext.getJobDetail();
        log.info(new StringBuilder()
                .append("nodeId : ").append(nodeId).append(", ")
                .append("jobName : ").append(jobDetail.getKey().getName()).append(", ")
                .append("description : ").append(jobDetail.getDescription())
        );
        knoxApprovalSyncService.synchronizeKnox();
    }
}
