package tech.easyflow.ai.documentimport.task;

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

/**
 * 文档导入中间快照清理调度器。
 *
 * @author Codex
 * @since 2026-08-04
 */
@Component
public class DocumentImportSnapshotCleanupMonitor {

    private final DocumentImportSnapshotCleanupService cleanupService;

    /**
     * 创建快照清理调度器。
     *
     * @param cleanupService 快照清理服务
     */
    public DocumentImportSnapshotCleanupMonitor(
        DocumentImportSnapshotCleanupService cleanupService) {
        this.cleanupService = cleanupService;
    }

    /**
     * 周期性重试到期的快照清理记录。
     */
    @Scheduled(
        fixedDelayString =
            "${easyflow.ai.document-import.snapshot-cleanup-interval:60s}",
        initialDelayString =
            "${easyflow.ai.document-import.snapshot-cleanup-initial-delay:60s}")
    @DistributedScheduledLock(
        key = "easyflow:schedule:document-import:snapshot-cleanup",
        leaseSeconds = 300L)
    public void cleanupPendingSnapshots() {
        cleanupService.processPendingCleanups();
    }
}
