package com.wzj.soopin.content.task;

import com.aizuda.snailjob.client.job.core.annotation.JobExecutor;
import com.wzj.soopin.content.service.VlogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 视频相关定时任务
 *
 * @author wzj
 */
@Slf4j
@Component
@JobExecutor(name = "vlogHotDataTask" )
public class VlogScheduledTask {

    @Autowired
    private VlogService vlogService;

    /**
     * 每天12点定时查询点赞最多的100条视频并存储到Redis
     * cron表达式：0 0 12 * * ? (每天12点执行)
     */
    public void jobExecute() {
        log.info("开始执行定时任务：查询点赞最多的100条视频并存储到Redis");
        try {
//            vlogService.cacheTopLikedVlogs(100);
            log.info("定时任务执行完成：成功缓存点赞最多的100条视频到Redis");
        } catch (Exception e) {
            log.error("定时任务执行失败：缓存点赞最多视频到Redis时发生异常", e);
        }
    }
}
