|
| 1 | +package com.retrip.map.infra.adapter.`in`.batch |
| 2 | + |
| 3 | +import com.retrip.map.domain.entity.Location |
| 4 | +import com.retrip.map.infra.adapter.out.search.elasticsearch.entity.LocationDocument |
| 5 | +import org.springframework.batch.core.Job |
| 6 | +import org.springframework.batch.core.Step |
| 7 | +import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing |
| 8 | +import org.springframework.batch.core.job.builder.JobBuilder |
| 9 | +import org.springframework.batch.core.repository.JobRepository |
| 10 | +import org.springframework.batch.core.step.builder.StepBuilder |
| 11 | +import org.springframework.beans.factory.annotation.Value |
| 12 | +import org.springframework.context.annotation.Bean |
| 13 | +import org.springframework.context.annotation.Configuration |
| 14 | +import org.springframework.transaction.PlatformTransactionManager |
| 15 | + |
| 16 | +@Configuration |
| 17 | +//@EnableBatchProcessing |
| 18 | +class MapBatchConfig( |
| 19 | + @Value("\${spring.batch.job.name}") |
| 20 | + private val jobName: String, |
| 21 | + private val reader: MapReader, |
| 22 | + private val processor: MapProcessor, |
| 23 | + private val writer: MapWriter, |
| 24 | +) { |
| 25 | + |
| 26 | + @Bean |
| 27 | + fun mapJob( |
| 28 | + jobRepository: JobRepository, |
| 29 | + mapStep: Step |
| 30 | + ): Job { |
| 31 | + return JobBuilder(jobName, jobRepository) |
| 32 | + .start(mapStep) |
| 33 | + .build() |
| 34 | + |
| 35 | + } |
| 36 | + |
| 37 | + @Bean |
| 38 | + fun mapStep( |
| 39 | + jobRepository: JobRepository, |
| 40 | + transactionManager: PlatformTransactionManager |
| 41 | + ): Step { |
| 42 | + return StepBuilder("map-step", jobRepository) |
| 43 | + .chunk<List<Location>, List<LocationDocument>>(10, transactionManager) |
| 44 | + .reader(reader) |
| 45 | + .processor(processor) |
| 46 | + .writer(writer) |
| 47 | + .build() |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | +} |
0 commit comments