package tech.easyflow.ai.documentimport.task;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import tech.easyflow.common.cache.DistributedScheduledLock;

/**
 * 知识库文档解析任务收敛器。
 *
 * <p>该调度器只负责轮询运行中的桥接解析任务，不承担提交任务职责。</p>
 *
 * @author Codex
 * @since 2026-04-15
 */
@Component
public class DocumentImportParseMonitor {

    private final KnowledgeDocumentImportTaskAppService appService;

    public DocumentImportParseMonitor(KnowledgeDocumentImportTaskAppService appService) {
        this.appService = appService;
    }

    /**
     * 定时收敛运行中的桥接解析任务状态。
     */
    @Scheduled(
        fixedDelayString = "${easyflow.ai.document-import.parse-monitor.fixed-delay:10000}",
        initialDelayString = "${easyflow.ai.document-import.parse-monitor.initial-delay:10000}"
    )
    @DistributedScheduledLock(key = "easyflow:schedule:document-import:parse-monitor", leaseSeconds = 300L)
    public void reconcileRunningParseTasks() {
        appService.monitorRunningParseTasks();
    }
}
