Add setter for ObservationConvention in Job/Step builders
Signed-off-by: Taeik Lim <sibera21@gmail.com> Resolves #4401
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
6fa4e45356
commit
7a5129647a
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,6 +34,8 @@ import org.springframework.batch.core.annotation.AfterJob;
|
||||
import org.springframework.batch.core.annotation.BeforeJob;
|
||||
import org.springframework.batch.core.job.AbstractJob;
|
||||
import org.springframework.batch.core.listener.JobListenerFactoryBean;
|
||||
import org.springframework.batch.core.observability.BatchJobObservationConvention;
|
||||
import org.springframework.batch.core.observability.DefaultBatchJobObservationConvention;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.support.ReflectionUtils;
|
||||
|
||||
@@ -102,6 +104,18 @@ public abstract class JobBuilderHelper<B extends JobBuilderHelper<B>> {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the job observation convention.
|
||||
* @param observationConvention the job observation convention (optional)
|
||||
* @return this to enable fluent chaining
|
||||
*/
|
||||
public B observationConvention(BatchJobObservationConvention observationConvention) {
|
||||
properties.observationConvention = observationConvention;
|
||||
@SuppressWarnings("unchecked")
|
||||
B result = (B) this;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the observation registry for the job.
|
||||
* @param observationRegistry the observation registry (optional)
|
||||
@@ -193,6 +207,10 @@ public abstract class JobBuilderHelper<B extends JobBuilderHelper<B>> {
|
||||
if (jobParametersValidator != null) {
|
||||
job.setJobParametersValidator(jobParametersValidator);
|
||||
}
|
||||
BatchJobObservationConvention observationConvention = properties.getObservationConvention();
|
||||
if (observationConvention != null) {
|
||||
job.setObservationConvention(observationConvention);
|
||||
}
|
||||
ObservationRegistry observationRegistry = properties.getObservationRegistry();
|
||||
if (observationRegistry != null) {
|
||||
job.setObservationRegistry(observationRegistry);
|
||||
@@ -221,6 +239,8 @@ public abstract class JobBuilderHelper<B extends JobBuilderHelper<B>> {
|
||||
|
||||
private JobRepository jobRepository;
|
||||
|
||||
private BatchJobObservationConvention observationConvention = new DefaultBatchJobObservationConvention();
|
||||
|
||||
private ObservationRegistry observationRegistry;
|
||||
|
||||
private MeterRegistry meterRegistry;
|
||||
@@ -236,6 +256,7 @@ public abstract class JobBuilderHelper<B extends JobBuilderHelper<B>> {
|
||||
this.name = properties.name;
|
||||
this.restartable = properties.restartable;
|
||||
this.jobRepository = properties.jobRepository;
|
||||
this.observationConvention = properties.observationConvention;
|
||||
this.observationRegistry = properties.observationRegistry;
|
||||
this.meterRegistry = properties.meterRegistry;
|
||||
this.jobExecutionListeners = new LinkedHashSet<>(properties.jobExecutionListeners);
|
||||
@@ -267,6 +288,14 @@ public abstract class JobBuilderHelper<B extends JobBuilderHelper<B>> {
|
||||
this.jobRepository = jobRepository;
|
||||
}
|
||||
|
||||
public BatchJobObservationConvention getObservationConvention() {
|
||||
return observationConvention;
|
||||
}
|
||||
|
||||
public void setObservationConvention(BatchJobObservationConvention observationConvention) {
|
||||
this.observationConvention = observationConvention;
|
||||
}
|
||||
|
||||
public ObservationRegistry getObservationRegistry() {
|
||||
return observationRegistry;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,8 @@ import org.springframework.batch.core.StepExecutionListener;
|
||||
import org.springframework.batch.core.annotation.AfterStep;
|
||||
import org.springframework.batch.core.annotation.BeforeStep;
|
||||
import org.springframework.batch.core.listener.StepListenerFactoryBean;
|
||||
import org.springframework.batch.core.observability.BatchStepObservationConvention;
|
||||
import org.springframework.batch.core.observability.DefaultBatchStepObservationConvention;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.AbstractStep;
|
||||
import org.springframework.batch.support.ReflectionUtils;
|
||||
@@ -70,6 +72,11 @@ public abstract class StepBuilderHelper<B extends StepBuilderHelper<B>> {
|
||||
return self();
|
||||
}
|
||||
|
||||
public B observationConvention(BatchStepObservationConvention observationConvention) {
|
||||
properties.observationConvention = observationConvention;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B observationRegistry(ObservationRegistry observationRegistry) {
|
||||
properties.observationRegistry = observationRegistry;
|
||||
return self();
|
||||
@@ -131,6 +138,11 @@ public abstract class StepBuilderHelper<B extends StepBuilderHelper<B>> {
|
||||
protected void enhance(AbstractStep step) {
|
||||
step.setJobRepository(properties.getJobRepository());
|
||||
|
||||
BatchStepObservationConvention observationConvention = properties.getObservationConvention();
|
||||
if (observationConvention != null) {
|
||||
step.setObservationConvention(observationConvention);
|
||||
}
|
||||
|
||||
ObservationRegistry observationRegistry = properties.getObservationRegistry();
|
||||
if (observationRegistry != null) {
|
||||
step.setObservationRegistry(observationRegistry);
|
||||
@@ -164,6 +176,8 @@ public abstract class StepBuilderHelper<B extends StepBuilderHelper<B>> {
|
||||
|
||||
private JobRepository jobRepository;
|
||||
|
||||
private BatchStepObservationConvention observationConvention = new DefaultBatchStepObservationConvention();
|
||||
|
||||
private ObservationRegistry observationRegistry = ObservationRegistry.NOOP;
|
||||
|
||||
private MeterRegistry meterRegistry = Metrics.globalRegistry;
|
||||
@@ -176,6 +190,7 @@ public abstract class StepBuilderHelper<B extends StepBuilderHelper<B>> {
|
||||
this.startLimit = properties.startLimit;
|
||||
this.allowStartIfComplete = properties.allowStartIfComplete;
|
||||
this.jobRepository = properties.jobRepository;
|
||||
this.observationConvention = properties.observationConvention;
|
||||
this.observationRegistry = properties.observationRegistry;
|
||||
this.meterRegistry = properties.meterRegistry;
|
||||
this.stepExecutionListeners = new ArrayList<>(properties.stepExecutionListeners);
|
||||
@@ -189,6 +204,14 @@ public abstract class StepBuilderHelper<B extends StepBuilderHelper<B>> {
|
||||
this.jobRepository = jobRepository;
|
||||
}
|
||||
|
||||
public BatchStepObservationConvention getObservationConvention() {
|
||||
return observationConvention;
|
||||
}
|
||||
|
||||
public void setObservationConvention(BatchStepObservationConvention observationConvention) {
|
||||
this.observationConvention = observationConvention;
|
||||
}
|
||||
|
||||
public ObservationRegistry getObservationRegistry() {
|
||||
return observationRegistry;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user