package link.at17.mid.tushare.task.scheduler;

import org.quartz.*;
import org.springframework.stereotype.Component;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import link.at17.mid.tushare.cache.CacheEvictionJob;
import link.at17.mid.tushare.task.TaskConstants;
import link.at17.mid.tushare.task.AutowireCapableJobFactory;

@Component
public class CacheDailyEvictionScheduler extends AutowireCapableJobFactory {

    @Resource(name="scheduler")
	Scheduler scheduler;
    
    @PostConstruct
    void onPostConstruct() throws SchedulerException {
        JobDetail cacheEviction = JobBuilder.newJob(CacheEvictionJob.class).withIdentity(TaskConstants.CACHE_EVICTION_JOB).build();              
        CronTrigger cacheDailyEvictionTrigger = 
                TriggerBuilder.newTrigger()
                .withIdentity(TaskConstants.CACHE_DAILY_EVICTION_TRIGGER)
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 * * ? ")).build();
        scheduler.scheduleJob(cacheEviction, cacheDailyEvictionTrigger);
        scheduler.start();
    }
    
}