Skip to content

Commit

Permalink
Merge pull request #180 from tukcomCD2024/feat/#179-scheduling-spring…
Browse files Browse the repository at this point in the history
…-batch

Feat/#179 �Spring Batch 스케쥴링 적용
  • Loading branch information
yeonjy authored Aug 2, 2024
2 parents 709b218 + bcb1771 commit ae7b3cf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication
public class BackendApplication {

public static void main(String[] args) {
SpringApplication.run(BackendApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.rollthedice.backend.batch;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.*;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class ScrapBatchScheduler {
private final JobLauncher jobLauncher;
private final ScrapJobConfig scrapJobConfig;
private final JobRepository jobRepository;
private final Step crawlingNewsUrlStep;
private final Step crawlingNewsContentStep;

// @Scheduled(cron = "0 0 6,12 * * *", zone = "Asia/Seoul") // DB 요금 문제로 개발 기간동안 주석 처리
public void runJob() {
JobParameters jobParameters = new JobParametersBuilder()
.addLong("time", System.currentTimeMillis())
.toJobParameters();
try {
jobLauncher.run(scrapJobConfig.scrapJob(jobRepository,
crawlingNewsUrlStep, crawlingNewsContentStep), jobParameters);
} catch (JobExecutionAlreadyRunningException | JobInstanceAlreadyCompleteException
| JobParametersInvalidException | org.springframework.batch.core.repository.JobRestartException e) {
log.error(e.getMessage());
}
}
}
2 changes: 1 addition & 1 deletion backend/core/src/main/resources/scoop-core-config

0 comments on commit ae7b3cf

Please sign in to comment.