- LogCleanupJob: 보존 기간 초과 배치 로그 삭제 Tasklet Job - 대상: batch_api_log(30일), Spring Batch 메타(90일), batch_failed_record/RESOLVED(90일), batch_recollection_history(90일) - application.yml에서 테이블별 보존 기간 설정 가능 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
70 lines
2.5 KiB
Java
70 lines
2.5 KiB
Java
package com.snp.batch.global.cleanup;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.batch.core.Job;
|
|
import org.springframework.batch.core.JobExecution;
|
|
import org.springframework.batch.core.JobExecutionListener;
|
|
import org.springframework.batch.core.Step;
|
|
import org.springframework.batch.core.job.builder.JobBuilder;
|
|
import org.springframework.batch.core.repository.JobRepository;
|
|
import org.springframework.batch.core.step.builder.StepBuilder;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.transaction.PlatformTransactionManager;
|
|
|
|
/**
|
|
* 배치 로그 정리 Job Config
|
|
*
|
|
* 스케줄: 매일 02:00 (0 0 2 * * ?)
|
|
*
|
|
* 동작:
|
|
* - 보존 기간이 지난 배치 로그 데이터를 삭제
|
|
* - batch_api_log (30일), Spring Batch 메타 (90일),
|
|
* batch_failed_record/RESOLVED (90일), batch_recollection_history (90일)
|
|
*/
|
|
@Slf4j
|
|
@Configuration
|
|
public class LogCleanupJobConfig {
|
|
|
|
private final JobRepository jobRepository;
|
|
private final PlatformTransactionManager transactionManager;
|
|
private final LogCleanupTasklet logCleanupTasklet;
|
|
|
|
public LogCleanupJobConfig(
|
|
JobRepository jobRepository,
|
|
PlatformTransactionManager transactionManager,
|
|
LogCleanupTasklet logCleanupTasklet) {
|
|
this.jobRepository = jobRepository;
|
|
this.transactionManager = transactionManager;
|
|
this.logCleanupTasklet = logCleanupTasklet;
|
|
}
|
|
|
|
@Bean(name = "logCleanupStep")
|
|
public Step logCleanupStep() {
|
|
return new StepBuilder("logCleanupStep", jobRepository)
|
|
.tasklet(logCleanupTasklet, transactionManager)
|
|
.build();
|
|
}
|
|
|
|
@Bean(name = "LogCleanupJob")
|
|
public Job logCleanupJob() {
|
|
log.info("Job 생성: LogCleanupJob");
|
|
|
|
return new JobBuilder("LogCleanupJob", jobRepository)
|
|
.listener(new JobExecutionListener() {
|
|
@Override
|
|
public void beforeJob(JobExecution jobExecution) {
|
|
log.info("[LogCleanupJob] 배치 로그 정리 Job 시작");
|
|
}
|
|
|
|
@Override
|
|
public void afterJob(JobExecution jobExecution) {
|
|
log.info("[LogCleanupJob] 배치 로그 정리 Job 완료 - 상태: {}",
|
|
jobExecution.getStatus());
|
|
}
|
|
})
|
|
.start(logCleanupStep())
|
|
.build();
|
|
}
|
|
}
|