package com.purui.prims.headless.server.schedule;

import com.purui.prims.headless.server.pojo.MetricFilter;
import com.purui.prims.headless.server.service.MetricLineageService;
import com.purui.prims.headless.server.service.MetricService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 指标血缘更新任务
 * @author charlie
 * @date 2024/7/29
 */
@Component
public class MetricLineageTask {

    private final MetricLineageService metricLineageService;

    private final MetricService metricService;

    public MetricLineageTask(MetricLineageService metricLineageService, MetricService metricService) {
        this.metricLineageService = metricLineageService;
        this.metricService = metricService;
    }
     // TODO: 交由定时任务管理器管理
     @Scheduled(cron = "0 0/5 * * * ?")
    public void executeTask() {
        // 仅已发布的指标计算血缘
        MetricFilter metricFilter = new MetricFilter();
        metricFilter.setIsPublish(1);
        metricService.getMetrics(metricFilter).forEach(metricLineageService::saveMetricLineage);
    }
}
