package com.nokia.tsl_data.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.nokia.tsl_data.service.TslCronTaskService;

import lombok.extern.slf4j.Slf4j;

/**
 * 在项目启动时根据配置启动任务
 */
@Slf4j
@Component
public class TaskRunner implements CommandLineRunner {

    @Value("${tslTask.isStarted}")
    private boolean isStarted;

    @Value("${tslTask.cronExpression}")
    private String cronExpression;

    @Autowired
    private TslCronTaskService cronTaskService;

    @Override
    public void run(String... args) throws Exception {
        cronTaskService.updateCronExpression(cronExpression);
        if (isStarted) {
            cronTaskService.startCronTask();
        }
        log.info("已启动定时任务");
    }

}
