package com.aip.gateway.api.scheduler;

import com.aip.gateway.api.config.ApplicationConfig;
import com.aip.gateway.api.utils.Elapsed;
import jakarta.annotation.PreDestroy;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


@Slf4j
@AllArgsConstructor
@EnableScheduling
@Component
public class SchedulerTask {

    private final ApplicationConfig config;

    @PreDestroy
    public void onShutDown() {
    }

    //@Scheduled(cron = "${application.schedule.aip-download:40 0/30 * * * *}")
    @Scheduled(cron = "* 0/30 * * * *")
    public void scheduleAipDownload() {
        if (!this.config.isStartSchedule()) {
            return;
        }
        Elapsed elapsed = new Elapsed();
        log.info("scheduleAipDownload: start. {}", Thread.currentThread().getName());
        log.info("scheduleAipDownload: ..end. {} ms. {}", elapsed.milliSeconds(), Thread.currentThread().getName());
    }

}
