package me.qwq.doghouse.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import me.qwq.doghouse.task.TaskSchedulerFactory;


@Configuration
public class QuartzConfig {
    @Autowired
    private TaskSchedulerFactory taskSchedulerFactory;

    @Bean("schedulerFactoryBean")
    SchedulerFactoryBean schedulerFactoryBean() {
        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        schedulerFactoryBean.setJobFactory( taskSchedulerFactory);
        return schedulerFactoryBean;
    }

    @Bean("scheduler")
    @DependsOn("schedulerFactoryBean")
    Scheduler scheduler(@Autowired SchedulerFactoryBean schedulerFactoryBean) {
        return schedulerFactoryBean.getScheduler();
    }
}
