修改更新模式

This commit is contained in:
xxy
2019-12-12 20:56:13 +08:00
parent 68f3ac055b
commit bd19c0733f
4 changed files with 138 additions and 43 deletions

View File

@ -0,0 +1,35 @@
package xyz.zinglizingli.common.listener;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import xyz.zinglizingli.common.crawl.BaseCrawlSource;
@Component
@Slf4j
@RequiredArgsConstructor
public class StartListener implements ApplicationListener<ContextRefreshedEvent> {
private final BaseCrawlSource crawlSource;
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
log.info("程序启动");
while (true) {
try {
log.debug("crawlBooks执行中。。。。。。。。。。。。");
crawlSource.parse();
Thread.sleep(1000 * 60 * 5);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
}

View File

@ -1,42 +0,0 @@
package xyz.zinglizingli.common.schedule;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.Charsets;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import xyz.zinglizingli.books.service.BookService;
import xyz.zinglizingli.common.crawl.BaseCrawlSource;
import xyz.zinglizingli.common.utils.RestTemplateUtil;
/**
* 更新书籍章节内容定时任务
*
* @author 11797
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class CrawlBooksSchedule {
private final BaseCrawlSource crawlSource;
/**
* 10分钟抓取一次
*/
@Scheduled(fixedRate = 1000 * 60 * 10)
public void crawBooks() {
log.debug("crawlBooksSchedule执行中。。。。。。。。。。。。");
crawlSource.parse();
}
}

View File

@ -5,7 +5,7 @@ spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
password: test123456
password:
# url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
# username: root
# password: test123456