From 73be43e1c56a7d30eb2d579e166348c4c148d060 Mon Sep 17 00:00:00 2001 From: xiongxiaoyang <773861846@qq.com> Date: Mon, 25 May 2020 17:11:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96es=E9=87=87=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../novel/core/schedule/BookToEsSchedule.java | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/novel-front/src/main/java/com/java2nb/novel/core/schedule/BookToEsSchedule.java b/novel-front/src/main/java/com/java2nb/novel/core/schedule/BookToEsSchedule.java index f74e56c..402ed4c 100644 --- a/novel-front/src/main/java/com/java2nb/novel/core/schedule/BookToEsSchedule.java +++ b/novel-front/src/main/java/com/java2nb/novel/core/schedule/BookToEsSchedule.java @@ -41,12 +41,12 @@ public class BookToEsSchedule { /** - * 2分钟导入一次 + * 10秒钟导入一次 */ - @Scheduled(fixedRate = 1000 * 60 * 2) + @Scheduled(fixedRate = 1000 * 10) public void saveToEs() { if (cacheService.get(CacheKey.ES_TRANS_LOCK) == null) { - cacheService.set(CacheKey.ES_TRANS_LOCK, "1", 60 * 60); + cacheService.set(CacheKey.ES_TRANS_LOCK, "1", 60 * 5); try { //查询需要更新的小说 Date lastDate = (Date) cacheService.getObject(CacheKey.ES_LAST_UPDATE_TIME); @@ -54,28 +54,22 @@ public class BookToEsSchedule { lastDate = new SimpleDateFormat("yyyy-MM-dd").parse("2020-01-01"); } - long count; - do { - List books = bookService.queryBookByUpdateTimeByPage(lastDate, 100); - for (Book book : books) { - //导入到ES - EsBookVO esBookVO = new EsBookVO(); - BeanUtils.copyProperties(book, esBookVO, "lastIndexUpdateTime"); - esBookVO.setLastIndexUpdateTime(new SimpleDateFormat("yyyy/MM/dd HH:mm").format(book.getLastIndexUpdateTime())); - Index action = new Index.Builder(esBookVO).index("novel").type("book").id(book.getId().toString()).build(); + List books = bookService.queryBookByUpdateTimeByPage(lastDate, 100); + for (Book book : books) { + //导入到ES + EsBookVO esBookVO = new EsBookVO(); + BeanUtils.copyProperties(book, esBookVO, "lastIndexUpdateTime"); + esBookVO.setLastIndexUpdateTime(new SimpleDateFormat("yyyy/MM/dd HH:mm").format(book.getLastIndexUpdateTime())); + Index action = new Index.Builder(esBookVO).index("novel").type("book").id(book.getId().toString()).build(); - jestClient.execute(action); + jestClient.execute(action); - lastDate = book.getUpdateTime(); - //1秒钟导入一本书,1分钟导入60本 - Thread.sleep(1000); + lastDate = book.getUpdateTime(); - } + } - count = books.size(); - } while (count == 100); cacheService.setObject(CacheKey.ES_LAST_UPDATE_TIME, lastDate);