package com.lanyuanxiaoyao.service.scheduler.quartz.compaction;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lanyuanxiaoyao.service.common.Constants;
import com.lanyuanxiaoyao.service.configuration.utils.QueueUtil;
import com.lanyuanxiaoyao.service.forest.service.InfoService;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

/**
 * 移除已完成表的跨天调度
 *
 * @author ZhangJiacheng
 * @date 2023-06-06
 */
@DisallowConcurrentExecution
public class RemoveScheduledJob extends BaseScheduleJob {
    private static final Logger logger = LoggerFactory.getLogger(RemoveScheduledJob.class);

    private final DiscoveryClient discoveryClient;
    private final InfoService infoService;
    private final ObjectMapper mapper;

    public RemoveScheduledJob(DiscoveryClient discoveryClient, InfoService infoService, Jackson2ObjectMapperBuilder builder) {
        this.discoveryClient = discoveryClient;
        this.infoService = infoService;

        this.mapper = builder.build();
    }

    @Override
    protected void executeInternal(JobExecutionContext context) {
        QueueUtil.remove(discoveryClient, mapper, Constants.COMPACTION_QUEUE_PRE, infoService.updatedVersionTables());
    }
}
