Skip to content

Commit 12070e7

Browse files
authored
Adjust JobScheduler init sequence to avoid job can not load from reg center (#1685)
1 parent 8d53b9e commit 12070e7

File tree

1 file changed

+16
-16
lines changed
  • elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule

1 file changed

+16
-16
lines changed

elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* the License. You may obtain a copy of the License at
88
*
99
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
10+
*
1111
* Unless required by applicable law or agreed to in writing, software
1212
* distributed under the License is distributed on an "AS IS" BASIS,
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -80,12 +80,12 @@ public JobScheduler(final CoordinatorRegistryCenter regCenter, final ElasticJob
8080
this.regCenter = regCenter;
8181
Collection<ElasticJobListener> jobListeners = getElasticJobListeners(jobConfig);
8282
setUpFacade = new SetUpFacade(regCenter, jobConfig.getJobName(), jobListeners);
83-
schedulerFacade = new SchedulerFacade(regCenter, jobConfig.getJobName());
84-
jobFacade = new LiteJobFacade(regCenter, jobConfig.getJobName(), jobListeners, findTracingConfiguration(jobConfig).orElse(null));
85-
validateJobProperties(jobConfig);
86-
jobExecutor = new ElasticJobExecutor(elasticJob, jobConfig, jobFacade);
8783
String jobClassName = JobClassNameProviderFactory.getProvider().getJobClassName(elasticJob);
8884
this.jobConfig = setUpFacade.setUpJobConfiguration(jobClassName, jobConfig);
85+
schedulerFacade = new SchedulerFacade(regCenter, jobConfig.getJobName());
86+
jobFacade = new LiteJobFacade(regCenter, jobConfig.getJobName(), jobListeners, findTracingConfiguration().orElse(null));
87+
validateJobProperties();
88+
jobExecutor = new ElasticJobExecutor(elasticJob, this.jobConfig, jobFacade);
8989
setGuaranteeServiceForElasticJobListeners(regCenter, jobListeners);
9090
jobScheduleController = createJobScheduleController();
9191
}
@@ -95,11 +95,11 @@ public JobScheduler(final CoordinatorRegistryCenter regCenter, final String elas
9595
this.regCenter = regCenter;
9696
Collection<ElasticJobListener> jobListeners = getElasticJobListeners(jobConfig);
9797
setUpFacade = new SetUpFacade(regCenter, jobConfig.getJobName(), jobListeners);
98-
schedulerFacade = new SchedulerFacade(regCenter, jobConfig.getJobName());
99-
jobFacade = new LiteJobFacade(regCenter, jobConfig.getJobName(), jobListeners, findTracingConfiguration(jobConfig).orElse(null));
100-
validateJobProperties(jobConfig);
101-
jobExecutor = new ElasticJobExecutor(elasticJobType, jobConfig, jobFacade);
10298
this.jobConfig = setUpFacade.setUpJobConfiguration(elasticJobType, jobConfig);
99+
schedulerFacade = new SchedulerFacade(regCenter, jobConfig.getJobName());
100+
jobFacade = new LiteJobFacade(regCenter, jobConfig.getJobName(), jobListeners, findTracingConfiguration().orElse(null));
101+
validateJobProperties();
102+
jobExecutor = new ElasticJobExecutor(elasticJobType, this.jobConfig, jobFacade);
103103
setGuaranteeServiceForElasticJobListeners(regCenter, jobListeners);
104104
jobScheduleController = createJobScheduleController();
105105
}
@@ -110,15 +110,15 @@ private Collection<ElasticJobListener> getElasticJobListeners(final JobConfigura
110110
.collect(Collectors.toList());
111111
}
112112

113-
private Optional<TracingConfiguration<?>> findTracingConfiguration(final JobConfiguration jobConfig) {
113+
private Optional<TracingConfiguration<?>> findTracingConfiguration() {
114114
return jobConfig.getExtraConfigurations().stream().filter(each -> each instanceof TracingConfiguration).findFirst().map(extraConfig -> (TracingConfiguration<?>) extraConfig);
115115
}
116116

117-
private void validateJobProperties(final JobConfiguration jobConfig) {
118-
validateJobErrorHandlerProperties(jobConfig);
117+
private void validateJobProperties() {
118+
validateJobErrorHandlerProperties();
119119
}
120120

121-
private void validateJobErrorHandlerProperties(final JobConfiguration jobConfig) {
121+
private void validateJobErrorHandlerProperties() {
122122
if (null != jobConfig.getJobErrorHandlerType()) {
123123
ElasticJobServiceLoader.newTypedServiceInstance(JobErrorHandlerPropertiesValidator.class, jobConfig.getJobErrorHandlerType(), jobConfig.getProps())
124124
.ifPresent(validator -> validator.validate(jobConfig.getProps()));
@@ -178,9 +178,9 @@ private void registerStartUpInfo() {
178178
setUpFacade.registerStartUpInfo(!jobConfig.isDisabled());
179179
}
180180

181-
/**
182-
* Shutdown job.
183-
*/
181+
/**
182+
* Shutdown job.
183+
*/
184184
public void shutdown() {
185185
schedulerFacade.shutdownInstance();
186186
jobExecutor.shutdown();

0 commit comments

Comments
 (0)