69 lines
2.5 KiB
Java
69 lines
2.5 KiB
Java
|
|
package com.snp.batch.global.partition;
|
||
|
|
|
||
|
|
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
|
||
|
|
*
|
||
|
|
* 스케줄: 매일 00:10 (0 10 0 * * ?)
|
||
|
|
*
|
||
|
|
* 동작:
|
||
|
|
* - Daily 파티션: 매일 실행
|
||
|
|
* - Monthly 파티션: 매월 말일에만 실행 (Job 내부에서 말일 감지)
|
||
|
|
*/
|
||
|
|
@Slf4j
|
||
|
|
@Configuration
|
||
|
|
public class PartitionManagerJobConfig {
|
||
|
|
|
||
|
|
private final JobRepository jobRepository;
|
||
|
|
private final PlatformTransactionManager transactionManager;
|
||
|
|
private final PartitionManagerTasklet partitionManagerTasklet;
|
||
|
|
|
||
|
|
public PartitionManagerJobConfig(
|
||
|
|
JobRepository jobRepository,
|
||
|
|
PlatformTransactionManager transactionManager,
|
||
|
|
PartitionManagerTasklet partitionManagerTasklet) {
|
||
|
|
this.jobRepository = jobRepository;
|
||
|
|
this.transactionManager = transactionManager;
|
||
|
|
this.partitionManagerTasklet = partitionManagerTasklet;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Bean(name = "partitionManagerStep")
|
||
|
|
public Step partitionManagerStep() {
|
||
|
|
return new StepBuilder("partitionManagerStep", jobRepository)
|
||
|
|
.tasklet(partitionManagerTasklet, transactionManager)
|
||
|
|
.build();
|
||
|
|
}
|
||
|
|
|
||
|
|
@Bean(name = "partitionManagerJob")
|
||
|
|
public Job partitionManagerJob() {
|
||
|
|
log.info("Job 생성: partitionManagerJob");
|
||
|
|
|
||
|
|
return new JobBuilder("partitionManagerJob", jobRepository)
|
||
|
|
.listener(new JobExecutionListener() {
|
||
|
|
@Override
|
||
|
|
public void beforeJob(JobExecution jobExecution) {
|
||
|
|
log.info("[partitionManagerJob] 파티션 관리 Job 시작");
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void afterJob(JobExecution jobExecution) {
|
||
|
|
log.info("[partitionManagerJob] 파티션 관리 Job 완료 - 상태: {}",
|
||
|
|
jobExecution.getStatus());
|
||
|
|
}
|
||
|
|
})
|
||
|
|
.start(partitionManagerStep())
|
||
|
|
.build();
|
||
|
|
}
|
||
|
|
}
|