package com.softwarebr.nunu.task;

import com.brframework.commondistributed.annotation.DistributedLock;
import com.softwarebr.nunu.service.SpiderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import static com.softwarebr.nunu.service.SpiderService.*;

/**
 * @author ljr
 * @date 2020/2/25 20:24
 * @description: 爬虫定时器
 */
@Component
@Slf4j
public class SpiderTask {

    @Autowired
    private SpiderService spiderService;

    @Scheduled(cron ="0 0 1 * * ?")
    @DistributedLock(key = "'TASK_GO_SPIDER_TYPE_TWO'", waitFor = false, throwException = false)
    public void savePolicyForUrlTwo(){
        spiderService.savePolicyForUrlTwo();
    }

    @Scheduled(cron ="0 0 1 * * ?")
    @DistributedLock(key = "'TASK_GO_SPIDER_TYPE_ONE_OF_ONE'", waitFor = false, throwException = false)
    public void fetchUrlTypeOneOfOne(){
        spiderService.getTopHtmlContentByUrlForUrlOne(SPIDER_URL_TYPE_ONE_OF_ONE, false);
    }

    @Scheduled(cron ="0 0 1 * * ?")
    @DistributedLock(key = "'TASK_GO_SPIDER_TYPE_ONE_OF_TWO'", waitFor = false, throwException = false)
    public void fetchUrlTypeOneOfTwo(){
        spiderService.getTopHtmlContentByUrlForUrlOne(SPIDER_URL_TYPE_ONE_OF_TWO, false);
    }

    @Scheduled(cron ="0 0 1 * * ?")
    @DistributedLock(key = "'TASK_GO_SPIDER_TYPE_ONE_OF_THREE'", waitFor = false, throwException = false)
    public void fetchUrlTypeOneOfThree(){
        spiderService.getTopHtmlContentByUrlForUrlOne(SPIDER_URL_TYPE_ONE_OF_THREE, true);
    }

    @Scheduled(cron ="0 0 1 * * ?")
    @DistributedLock(key = "'TASK_GO_SPIDER_TYPE_ONE_OF_FOUR'", waitFor = false, throwException = false)
    public void fetchUrlTypeOneOfFor(){
        spiderService.getTopHtmlContentByUrlForUrlOne(SPIDER_URL_TYPE_ONE_OF_FOUR, true);
    }
}
