1
1
/*
2
- * Copyright 2006-2022 the original author or authors.
2
+ * Copyright 2006-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
34
34
import org .springframework .batch .core .annotation .BeforeJob ;
35
35
import org .springframework .batch .core .job .AbstractJob ;
36
36
import org .springframework .batch .core .listener .JobListenerFactoryBean ;
37
+ import org .springframework .batch .core .observability .BatchJobObservationConvention ;
38
+ import org .springframework .batch .core .observability .DefaultBatchJobObservationConvention ;
37
39
import org .springframework .batch .core .repository .JobRepository ;
38
40
import org .springframework .batch .support .ReflectionUtils ;
39
41
@@ -102,6 +104,18 @@ public B repository(JobRepository jobRepository) {
102
104
return result ;
103
105
}
104
106
107
+ /**
108
+ * Sets the job observation convention.
109
+ * @param observationConvention the job observation convention (optional)
110
+ * @return this to enable fluent chaining
111
+ */
112
+ public B observationConvention (BatchJobObservationConvention observationConvention ) {
113
+ properties .observationConvention = observationConvention ;
114
+ @ SuppressWarnings ("unchecked" )
115
+ B result = (B ) this ;
116
+ return result ;
117
+ }
118
+
105
119
/**
106
120
* Sets the observation registry for the job.
107
121
* @param observationRegistry the observation registry (optional)
@@ -193,6 +207,10 @@ protected void enhance(AbstractJob job) {
193
207
if (jobParametersValidator != null ) {
194
208
job .setJobParametersValidator (jobParametersValidator );
195
209
}
210
+ BatchJobObservationConvention observationConvention = properties .getObservationConvention ();
211
+ if (observationConvention != null ) {
212
+ job .setObservationConvention (observationConvention );
213
+ }
196
214
ObservationRegistry observationRegistry = properties .getObservationRegistry ();
197
215
if (observationRegistry != null ) {
198
216
job .setObservationRegistry (observationRegistry );
@@ -221,6 +239,8 @@ public static class CommonJobProperties {
221
239
222
240
private JobRepository jobRepository ;
223
241
242
+ private BatchJobObservationConvention observationConvention = new DefaultBatchJobObservationConvention ();
243
+
224
244
private ObservationRegistry observationRegistry ;
225
245
226
246
private MeterRegistry meterRegistry ;
@@ -236,6 +256,7 @@ public CommonJobProperties(CommonJobProperties properties) {
236
256
this .name = properties .name ;
237
257
this .restartable = properties .restartable ;
238
258
this .jobRepository = properties .jobRepository ;
259
+ this .observationConvention = properties .observationConvention ;
239
260
this .observationRegistry = properties .observationRegistry ;
240
261
this .meterRegistry = properties .meterRegistry ;
241
262
this .jobExecutionListeners = new LinkedHashSet <>(properties .jobExecutionListeners );
@@ -267,6 +288,14 @@ public void setJobRepository(JobRepository jobRepository) {
267
288
this .jobRepository = jobRepository ;
268
289
}
269
290
291
+ public BatchJobObservationConvention getObservationConvention () {
292
+ return observationConvention ;
293
+ }
294
+
295
+ public void setObservationConvention (BatchJobObservationConvention observationConvention ) {
296
+ this .observationConvention = observationConvention ;
297
+ }
298
+
270
299
public ObservationRegistry getObservationRegistry () {
271
300
return observationRegistry ;
272
301
}
0 commit comments