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;

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

    @Value("${tslTask.isStarted:false}")
    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();
        }
    }

}
