package com.tsi.sig.server.scheduler;

import com.tsi.sig.server.app.AppUtils;
import com.tsi.sig.server.websocket.AllTopicCvimHandler;
import com.tsi.sig.server.websocket.OneTopicCvimHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

@Slf4j
@EnableScheduling
@Component
public class TsiSigScheduler {

    public TsiSigScheduler() {
    }

    @PreDestroy
    public void onShutDown() {
    }

    @Async
    @Scheduled(cron = "0 * * * * *")  // 1분 주기 작업 실행
    public void jobLoadDatabase() {
        AllTopicCvimHandler allTopicCvimHandler = (AllTopicCvimHandler) AppUtils.getBean(AllTopicCvimHandler.class);
        OneTopicCvimHandler oneTopicCvimHandler = (OneTopicCvimHandler) AppUtils.getBean(OneTopicCvimHandler.class);
        try {
            allTopicCvimHandler.start();
            oneTopicCvimHandler.start();
        } catch (Exception e) {
        }
    }

}
