Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (#1) : scheduled delay of 10 seconds #6

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/gwangjang/server/KeywordServiceApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableBatchProcessing
@EnableScheduling
@EnableAsync
public class KeywordServiceApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void saveOrUpdateWord(List<Token> tokens , int id) {
for (Token token : tokens) {
String word = token.getMorph();
System.out.println("save " + word);
Morpheme existingWord = morphemeRepository.findByWordAndIssueId(word,3);
Morpheme existingWord = morphemeRepository.findByWordAndIssueId(word,id);
if (existingWord != null) {
// 단어가 이미 존재하면 count를 업데이트
existingWord.setCount(existingWord.getCount() + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public String naverAPI(String name) throws JsonProcessingException {
e.printStackTrace();
}
}
try {
Thread.sleep(1000); // 100 milliseconds delay
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
// try {
// Thread.sleep(1000); // 100 milliseconds delay
// } catch (InterruptedException e) {
// Thread.currentThread().interrupt();
// }

return rslt.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.swagger.annotations.ApiOperation;
import kr.co.shineware.nlp.komoran.model.Token;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -22,17 +23,33 @@ public class MorphemeController {
private final NewsAPIService newsAPIService;
private final MorphemeService morphemeService;
//@GetMapping("/analysis/{msg}")
@Scheduled(fixedDelay = 30000)

//@Scheduled(cron = "* * * * * *")
@GetMapping("/test")
public String analysis() throws JsonProcessingException {
String newsList1 = newsAPIService.naverAPI("주 69시간 근로시간 제도 개편");
String newsList2 = newsAPIService.naverAPI("이태원 참사");
String newsList3 = newsAPIService.naverAPI("국민연금 개혁");
List<Token> newsAnalysis1 =newsAPIService.analysis(newsList1);
List<Token> newsAnalysis2 =newsAPIService.analysis(newsList2);
List<Token> newsAnalysis3 =newsAPIService.analysis(newsList3);
morphemeService.saveOrUpdateWord(newsAnalysis1, 100 );
morphemeService.saveOrUpdateWord(newsAnalysis2, 200);
morphemeService.saveOrUpdateWord(newsAnalysis3, 300);
String newsList1 = newsAPIService.naverAPI("주 69시간 근로시간 제도 개편");
String newsList2 = newsAPIService.naverAPI("이태원 참사");
String newsList3 = newsAPIService.naverAPI("국민연금 개혁");

asyncMethodNews(newsList1);
asyncMethodNews2(newsList2);
asyncMethodNews3(newsList3);
return "success";
}
@Async
public void asyncMethodNews(String newsList1) throws JsonProcessingException {
List<Token> newsAnalysis1 =newsAPIService.analysis(newsList1);
morphemeService.saveOrUpdateWord(newsAnalysis1, 100 );
}
@Async
public void asyncMethodNews2(String newsList2) throws JsonProcessingException {

List<Token> newsAnalysis2 =newsAPIService.analysis(newsList2);
morphemeService.saveOrUpdateWord(newsAnalysis2, 200);
}
@Async
public void asyncMethodNews3(String newsList3) throws JsonProcessingException {
List<Token> newsAnalysis3 =newsAPIService.analysis(newsList3);
morphemeService.saveOrUpdateWord(newsAnalysis3, 300);
}
}