Skip to content

Commit

Permalink
Merge pull request #3 from kusitms-28th-Meetup-E/feat/batch
Browse files Browse the repository at this point in the history
feat(#1) : scheduled cron
  • Loading branch information
eojinny authored Nov 14, 2023
2 parents 5bc15e2 + a80896a commit c4c15b6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
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

0 comments on commit c4c15b6

Please sign in to comment.