package com.zhongshu.card.server.core.init;

import com.zhongshu.card.server.core.service.schedule.ScheduleTaskConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * 定时任务初始化
 *
 * @author TRX
 * @date 2024/6/3
 */
@Component
@Slf4j
public class ScheduleTaskiInit implements CommandLineRunner {

    @Autowired
    private ScheduleTaskConfigService scheduleTaskConfigService;

    @Override
    public void run(String... args) throws Exception {
        CompletableFuture.runAsync(() -> {
            try {
                log.info("加载定时任务");
                TimeUnit.SECONDS.sleep(10);
                scheduleTaskConfigService.initAllTaskLockSchedule();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
