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

feat(#1) : scheduled cron #3

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
4 changes: 4 additions & 0 deletions src/main/java/gwangjang/server/KeywordServiceApplication.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package gwangjang.server;

import gwangjang.server.domain.morpheme.presentation.MorphemeController;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableBatchProcessing
@EnableScheduling
public class KeywordServiceApplication {

public static void main(String[] args) {

SpringApplication.run(KeywordServiceApplication.class, args);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package gwangjang.server.domain.morpheme.presentation;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class JobController {

private final JobLauncher jobLauncher;
private final Job apiJob; // Inject the job bean you want to execute

@Autowired
public JobController(JobLauncher jobLauncher, Job apiJob) {
this.jobLauncher = jobLauncher;
this.apiJob = apiJob;
}

@GetMapping("/runJob")
public String runJob() throws Exception {
JobExecution jobExecution = jobLauncher.run(apiJob, new JobParameters());
return "Job Execution Status: " + jobExecution.getStatus();
}
}
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.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -20,8 +21,9 @@ public class MorphemeController {

private final NewsAPIService newsAPIService;
private final MorphemeService morphemeService;
@GetMapping("/analysis/{msg}")
public String analysis(@PathVariable String msg) throws JsonProcessingException {
//@GetMapping("/analysis/{msg}")
@Scheduled(cron = "* * * * * 2")
public String analysis() throws JsonProcessingException {
String newsList1 = newsAPIService.naverAPI("주 69시간 근로시간 제도 개편");
String newsList2 = newsAPIService.naverAPI("이태원 참사");
String newsList3 = newsAPIService.naverAPI("국민연금 개혁");
Expand Down