package com.lanyuanxiaoyao.service.check;

import com.lanyuanxiaoyao.service.check.actions.Checker;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

/**
 * 启动类
 *
 * @author lanyuanxiaoyao
 * @date 2024-02-22
 */
@SpringBootApplication
public class CheckApplication implements ApplicationRunner {
    private static final Logger logger = LoggerFactory.getLogger(CheckApplication.class);
    private final ApplicationContext applicationContext;

    public CheckApplication(ApplicationContext applicationContext) {this.applicationContext = applicationContext;}

    public static void main(String[] args) {
        SpringApplication.run(CheckApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        Map<String, Checker> beans = applicationContext.getBeansOfType(Checker.class);
        for (Checker checker : beans.values()) {
            logger.info("Execute checker: {}", checker.description());
            checker.check();
        }
    }
}
