I need to create scheduled batch job for processing some data nightly.
(我需要创建计划的批处理作业以每晚处理一些数据。)
I'm trying to use spring batch jobs and schedule it using cron expression. (我正在尝试使用春季批处理作业,并使用cron表达式计划它。)
It should run every night on 1:00 AM. (它应该每天晚上1:00 AM运行。)
I'm interested what will happen if application will restart at that time and will miss start time. (我对如果应用程序在那时重新启动而错过启动时间会发生什么感兴趣。)
For example let's say that application was down for 30 minutes it shut down on 00:45 AM and started back 01:15 AM will scheduled job start or will I need to manually run it. (例如,假设应用程序关闭了30分钟,它在00:45 AM时关闭并在01:15 AM开始启动,这将排定作业开始时间,或者我需要手动运行它。)
Does spring manage this? (春天可以处理这个吗?)
I wasn't able to find any information about this. (我找不到有关此的任何信息。)
Is there any possibility to automatically manage such cases? (是否有可能自动管理此类案件?)
Below I provide example configuration of my job: (下面,我提供工作的示例配置:)
const val CHUNK_SIZE = 20
const val JOB_NAME = "reallyAwesomeJobName"
@Configuration
class ReallyAwesomeJobConfiguration(
private val jobLauncher: JobLauncher,
private val jobBuilderFactory: JobBuilderFactory,
private val stepBuilderFactory: StepBuilderFactory
) {
@Bean
fun reallyAwesomeJob(): Job = jobBuilderFactory
.get(JOB_NAME)
.incrementer(RunIdIncrementer())
.start(step1())
.next(step2())
.build()
@Bean
fun step1(): Step = stepBuilderFactory
.get("step1")
.chunk<ItemDto, ItemProcessingResultDto>(CHUNK_SIZE)
.reader(reader())
.processor(itemProcessor1())
.writer(writer())
.build()
@Bean
fun step2(): Step = stepBuilderFactory
.get("step2")
.chunk<ItemDto, ItemProcessingResultDto>(CHUNK_SIZE)
.reader(reader())
.processor(itemProcessor2())
.writer(writer())
.build()
@Bean
fun reader() = CustomItemReader()
@Bean
fun itemProcessor1() = ItemProcessor1()
@Bean
fun itemProcessor2() = ItemProcessor2()
@Bean
fun writer() = CustomItemWriter()
@Scheduled(cron = "0 0 1 * * *")
fun perform() {
jobLauncher.run(
reallyAwesomeJob(),
JobParametersBuilder()
.addDate("executionDate", Date())
.toJobParameters()
)
}
}
ask by GROX13 translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…