mirror of
https://github.com/201206030/novel.git
synced 2025-06-24 08:06:39 +00:00
修改更新模式
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -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
|
||||
|
Reference in New Issue
Block a user