diff --git a/src/main/java/com/kusitms/jipbap/event/batch/EventLogClearConfig.java b/src/main/java/com/kusitms/jipbap/event/batch/EventLogClearConfig.java index 51c2d7e..ac9fcf7 100644 --- a/src/main/java/com/kusitms/jipbap/event/batch/EventLogClearConfig.java +++ b/src/main/java/com/kusitms/jipbap/event/batch/EventLogClearConfig.java @@ -54,7 +54,7 @@ public Job eventLogClearJob(JobRepository jobRepository, PlatformTransactionMana @JobScope public Step eventLogClearStep(JobRepository jobRepository, PlatformTransactionManager transactionManager) { return new StepBuilder(STEP_NAME, jobRepository) - .chunk(5, transactionManager) // chunkSize: 몇 개 단위로 데이터를 처리할 것인지 지정. 참고로 파라미터로 받아서 사용할 수는 없다. + .chunk(500, transactionManager) // chunkSize: 몇 개 단위로 데이터를 처리할 것인지 지정. 참고로 파라미터로 받아서 사용할 수는 없다. .reader(eventLogClearReader()) .processor(eventLogClearProcessor()) .writer(eventLogClearWriter()) @@ -100,9 +100,9 @@ public ItemReader eventLogClearReader() { .repository(eventLogRepository) .methodName("findByCreatedAtBefore") .arguments(List.of(dateTime)) // 의미없는 PageRequest 전달 - .pageSize(5) // chunkSize와 일치하게 설정 + .pageSize(500) // chunkSize와 일치하게 설정 .sorts(Collections.singletonMap("id", Sort.Direction.ASC)) - .build();제 + .build(); } } diff --git a/src/main/java/com/kusitms/jipbap/event/scheduler/ClearJobScheduler.java b/src/main/java/com/kusitms/jipbap/event/scheduler/ClearJobScheduler.java new file mode 100644 index 0000000..a6cb15c --- /dev/null +++ b/src/main/java/com/kusitms/jipbap/event/scheduler/ClearJobScheduler.java @@ -0,0 +1,36 @@ +package com.kusitms.jipbap.event.scheduler; + +import lombok.RequiredArgsConstructor; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.JobParameter; +import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.JobParametersInvalidException; +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.JobRestartException; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.Collections; + +/** + * 스케줄러를 통해서 Job 실행 + */ +@Component +@RequiredArgsConstructor +public class ClearJobScheduler { + + private final Job eventLogClearJob; + private final JobLauncher jobLauncher; // 스케줄링을 활용하여 Job 실행 + + @Scheduled(cron = "0 3 15 * * *") // 매일 특정 시간(3시 15분)에 실행 + public void testJobRun() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { + + JobParameters jobParameters = new JobParameters( + Collections.singletonMap("requestTime", new JobParameter(System.currentTimeMillis(), Long.class)) + ); + + jobLauncher.run(eventLogClearJob, jobParameters); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7829ad4..28aeb46 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -46,7 +46,7 @@ spring: initialize-schema: always job: name: eventLogClearJob -# enabled: false # Job 실행을 스케줄러에게 위임하기 위하여 설정 + enabled: false # Job 실행을 스케줄러에게 위임하기 위하여 설정 cloud: aws: