[NO-ISSUE] Fix bug
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.processor.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -48,7 +47,8 @@ public class CrawlAPIController {
|
||||
ppomppuRSSFeedService.getArticles(boardName)
|
||||
.map(e -> ppomppuArticleService.filterOnlyNewArticles(boardName, e))
|
||||
.map(e -> ppomppuArticleService.save(boardName, e))
|
||||
.flatMap(messageSenderService::sendMessageToSlack);
|
||||
.filter(e -> !e.isEmpty())
|
||||
.flatMap(messageSenderService::sendBlockMessageToSlack);
|
||||
|
||||
return publishedMessages.then(Mono.just(APIResponse.success(result.done())));
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.domain.PpomppuArticle;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.BlockMessageDTO;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.SimpleMessageDTO;
|
||||
|
||||
/**
|
||||
@@ -20,21 +21,22 @@ public final class PpomppuArticleTransformer {
|
||||
|
||||
private PpomppuArticleTransformer() {}
|
||||
|
||||
private static final String MESSAGE_FORMAT_V1 = "%s)) `%s` <%s:LINK>";
|
||||
private static final String MESSAGE_FORMAT_V1 = "%s)) <%s|LINK> `%s` ";
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
.withZone(ZoneId.of("Asia/Seoul"));
|
||||
|
||||
public static final Function<PpomppuArticle, SimpleMessageDTO> TRANSFORM_TO_MESSAGE_DTO = entity ->
|
||||
public static final Function<PpomppuArticle, SimpleMessageDTO> TRANSFORM_TO_MESSAGE_DTO = article ->
|
||||
SimpleMessageDTO.builder()
|
||||
.requestedAt(Instant.now())
|
||||
.publishedAt(entity.getRegisteredAt())
|
||||
.title(String.format(MESSAGE_FORMAT_V1, entity.getBoardName().getMenuName(), entity.getTitle()))
|
||||
.body(entity.getArticleUrl())
|
||||
.publishedAt(article.getRegisteredAt())
|
||||
.title(String.format(MESSAGE_FORMAT_V1,
|
||||
article.getBoardName().getMenuName(), article.getArticleUrl(), article.getTitle()))
|
||||
.body(article.getArticleUrl())
|
||||
.build();
|
||||
|
||||
// https://stackoverflow.com/questions/24882927/using-streams-to-convert-a-list-of-objects-into-a-string-obtained-from-the-tostr
|
||||
public static SimpleMessageDTO transform(List<PpomppuArticle> articles) {
|
||||
public static SimpleMessageDTO transformToSimpleMessage(List<PpomppuArticle> articles) {
|
||||
Instant requestedAt = Instant.now();
|
||||
String body = articles.stream()
|
||||
.map(PpomppuArticleTransformer::convertToInlineMessage)
|
||||
@@ -46,8 +48,20 @@ public final class PpomppuArticleTransformer {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static BlockMessageDTO transformToBlockMessage(List<PpomppuArticle> articles) {
|
||||
Instant requestedAt = Instant.now();
|
||||
List<String> body = articles.stream()
|
||||
.map(PpomppuArticleTransformer::convertToInlineMessage)
|
||||
.collect(Collectors.toList());
|
||||
return BlockMessageDTO.builder()
|
||||
.requestedAt(requestedAt)
|
||||
.title(DATE_TIME_FORMATTER.format(requestedAt))
|
||||
.blocks(body)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static String convertToInlineMessage(PpomppuArticle article) {
|
||||
return String.format(MESSAGE_FORMAT_V1,
|
||||
article.getBoardName().getMenuName(), article.getTitle(), article.getArticleUrl());
|
||||
article.getBoardName().getMenuName(), article.getArticleUrl(), article.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.reactive.function.client.WebClientRequestException;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.dto.constant.WebClientPropertiesUnitName;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.BlockMessageDTO;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.SimpleMessageDTO;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.webclient.factory.WebClientFilterFactory;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.webclient.factory.WebFluxExchangeStragiesFactory;
|
||||
@@ -42,9 +43,22 @@ public class MessageSenderAPIClient {
|
||||
.build();
|
||||
}
|
||||
|
||||
public Mono<String> sendMessageToSlack(SimpleMessageDTO dto) {
|
||||
public Mono<String> sendSimpleMessageToSlack(SimpleMessageDTO dto) {
|
||||
return webClient.post()
|
||||
.uri("/api/v1/messages/sendMessage/messengers/slack")
|
||||
.uri("/api/v1/messages/sendSimpleMessage/messengers/slack")
|
||||
.bodyValue(dto)
|
||||
.exchangeToMono(e -> e.bodyToMono(new ParameterizedTypeReference<String>() {}))
|
||||
.publishOn(Schedulers.boundedElastic())
|
||||
.onErrorResume(WebClientRequestException.class, t -> {
|
||||
log.info("Exception occured, ignoring. : {}", t.getClass().getSimpleName());
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public Mono<String> sendBlockMessageToSlack(BlockMessageDTO dto) {
|
||||
return webClient.post()
|
||||
.uri("/api/v1/messages/sendBlockMessage/messengers/slack")
|
||||
.bodyValue(dto)
|
||||
.exchangeToMono(e -> e.bodyToMono(new ParameterizedTypeReference<String>() {}))
|
||||
.publishOn(Schedulers.boundedElastic())
|
||||
|
||||
@@ -27,12 +27,16 @@ public class MessageSenderService {
|
||||
this.messageSenderAPIClient = messageSenderAPIClient;
|
||||
}
|
||||
|
||||
public Mono<String> sendMessageToSlack(PpomppuArticle article) {
|
||||
return messageSenderAPIClient.sendMessageToSlack(PpomppuArticleTransformer.TRANSFORM_TO_MESSAGE_DTO.apply(article));
|
||||
public Mono<String> sendSimpleMessageToSlack(PpomppuArticle article) {
|
||||
return messageSenderAPIClient.sendSimpleMessageToSlack(PpomppuArticleTransformer.TRANSFORM_TO_MESSAGE_DTO.apply(article));
|
||||
}
|
||||
|
||||
public Mono<String> sendMessageToSlack(List<PpomppuArticle> articles) {
|
||||
return messageSenderAPIClient.sendMessageToSlack(PpomppuArticleTransformer.transform(articles));
|
||||
public Mono<String> sendSimpleMessageToSlack(List<PpomppuArticle> articles) {
|
||||
return messageSenderAPIClient.sendSimpleMessageToSlack(PpomppuArticleTransformer.transformToSimpleMessage(articles));
|
||||
}
|
||||
|
||||
public Mono<String> sendBlockMessageToSlack(List<PpomppuArticle> articles) {
|
||||
return messageSenderAPIClient.sendBlockMessageToSlack(PpomppuArticleTransformer.transformToBlockMessage(articles));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,10 @@ public class PpomppuArticleService {
|
||||
|
||||
// save PpomppuBoardFeedStatus
|
||||
Optional<PpomppuBoardFeedStatus> boardFeedStatus = ppomppuBoardFeedStatusRepository.findByBoardName(boardName);
|
||||
log.info("boardName: {}, isPresent?: {}", boardName, boardFeedStatus.isPresent());
|
||||
log.info("[save] boardName: {}, isPresent?: {}, latestArticleId: {}",
|
||||
boardName, boardFeedStatus.isPresent(), latestArticleId);
|
||||
log.info("[save] articles count: {}, article ids: {}",
|
||||
articles.size(), articles.stream().map(PpomppuArticle::getArticleId).toArray());
|
||||
boardFeedStatus.ifPresentOrElse(e -> {
|
||||
if (latestArticleId.longValue() > 0L) {
|
||||
e.updateArticleId(latestArticleId);
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.myoa.engineering.crawl.ppomppu.processor.domain.PpomppuArticle;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.dto.PpomppuArticleParser;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.infrastructure.client.PpomppuBoardFeedRetriever;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jsoup.Jsoup;
|
||||
@@ -34,6 +36,7 @@ public class PpomppuFeedService {
|
||||
// .doOnNext(e -> log.info("pre tbody - {}", e.html()));
|
||||
return extractArticlesFromTbody(tbody).map(this::convertFromElement)
|
||||
.map(e -> e.updateBoardName(boardName))
|
||||
.sort(Comparator.comparing(PpomppuArticle::getArticleId))
|
||||
// .doOnNext(e -> log.info("parsed Result: {}", e))
|
||||
.collectList();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ spring:
|
||||
activate:
|
||||
on-profile: development
|
||||
import:
|
||||
- "configserver:http://192.168.0.100:20085"
|
||||
- "configserver:http://192.168.0.100:11080"
|
||||
|
||||
|
||||
server:
|
||||
|
||||
@@ -8,7 +8,7 @@ spring:
|
||||
group:
|
||||
local: "local,datasource-local,webclient-local"
|
||||
development: "development,datasource-development,webclient-development"
|
||||
production: "production, datasource-production,webclient-production"
|
||||
production: "production,datasource-production,webclient-production"
|
||||
freemarker:
|
||||
enabled: false
|
||||
|
||||
@@ -22,4 +22,4 @@ management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: refresh
|
||||
include: refresh,health
|
||||
|
||||
Reference in New Issue
Block a user