Skip to content

Commit aadda32

Browse files
author
Binbing Hou
committed
Address the missing packages of TaskExecutorCustomizer and TaskSchedulerCustomizer
1 parent 87d5849 commit aadda32

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

genie-agent/src/main/java/com/netflix/genie/agent/spring/autoconfigure/AgentAutoConfiguration.java

+40-20
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import com.netflix.genie.agent.utils.locks.impl.FileLockFactory;
2424
import com.netflix.genie.common.internal.util.GenieHostInfo;
2525
import com.netflix.genie.common.internal.util.HostnameUtil;
26+
import org.springframework.beans.factory.config.BeanPostProcessor;
2627
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
28+
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
2729
import org.springframework.boot.context.properties.EnableConfigurationProperties;
28-
import org.springframework.boot.task.TaskExecutorCustomizer;
29-
import org.springframework.boot.task.TaskSchedulerCustomizer;
3030
import org.springframework.context.annotation.Bean;
3131
import org.springframework.context.annotation.Configuration;
3232
import org.springframework.context.annotation.Lazy;
@@ -51,6 +51,9 @@
5151
)
5252
public class AgentAutoConfiguration {
5353

54+
// Common bean names used by Spring Boot
55+
private static final String TASK_SCHEDULER_BEAN_NAME = "taskScheduler";
56+
5457
/**
5558
* Provide a bean of type {@link GenieHostInfo} if none already exists.
5659
*
@@ -151,34 +154,51 @@ public TaskScheduler heartBeatServiceTaskScheduler(final AgentProperties agentPr
151154
}
152155

153156
/**
154-
* Customizer for Spring's task executor.
157+
* Bean post processor to customize the task executor created by Spring Boot.
158+
* This provides the functionality of TaskExecutorCustomizer which is no longer available in AWS Cloud v3.
155159
*
156160
* @param agentProperties the agent properties
157-
* @return a customizer for the task executor
161+
* @return A BeanPostProcessor that customizes task executors
158162
*/
159-
@Bean
160-
TaskExecutorCustomizer taskExecutorCustomizer(final AgentProperties agentProperties) {
161-
return taskExecutor -> {
162-
taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
163-
taskExecutor.setAwaitTerminationSeconds(
164-
(int) agentProperties.getShutdown().getSystemExecutorLeeway().getSeconds()
165-
);
163+
@Bean(name = "taskExecutorCustomizer")
164+
public BeanPostProcessor taskExecutorCustomizer(final AgentProperties agentProperties) {
165+
return new BeanPostProcessor() {
166+
@Override
167+
public Object postProcessAfterInitialization(final Object bean, final String beanName) {
168+
// Customize the application task executor
169+
if (bean instanceof ThreadPoolTaskExecutor executor && TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME.equals(beanName)) {
170+
executor.setWaitForTasksToCompleteOnShutdown(true);
171+
executor.setAwaitTerminationSeconds(
172+
(int) agentProperties.getShutdown().getSystemExecutorLeeway().getSeconds()
173+
);
174+
}
175+
return bean;
176+
}
166177
};
167178
}
168179

169180
/**
170-
* Customizer for Spring's task scheduler.
181+
* Bean post processor to customize the task scheduler created by Spring Boot.
182+
* This provides the functionality of TaskSchedulerCustomizer which is no longer available in AWS Cloud v3.
171183
*
172184
* @param agentProperties the agent properties
173-
* @return a customizer for the task scheduler
185+
* @return A BeanPostProcessor that customizes task schedulers
174186
*/
175-
@Bean
176-
TaskSchedulerCustomizer taskSchedulerCustomizer(final AgentProperties agentProperties) {
177-
return taskScheduler -> {
178-
taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
179-
taskScheduler.setAwaitTerminationSeconds(
180-
(int) agentProperties.getShutdown().getSystemSchedulerLeeway().getSeconds()
181-
);
187+
@Bean(name = "taskSchedulerCustomizer")
188+
public BeanPostProcessor taskSchedulerCustomizer(final AgentProperties agentProperties) {
189+
return new BeanPostProcessor() {
190+
@Override
191+
public Object postProcessAfterInitialization(final Object bean, final String beanName) {
192+
// Customize the task scheduler
193+
if (bean instanceof ThreadPoolTaskScheduler scheduler
194+
&& TASK_SCHEDULER_BEAN_NAME.equals(beanName)) {
195+
scheduler.setWaitForTasksToCompleteOnShutdown(true);
196+
scheduler.setAwaitTerminationSeconds(
197+
(int) agentProperties.getShutdown().getSystemSchedulerLeeway().getSeconds()
198+
);
199+
}
200+
return bean;
201+
}
182202
};
183203
}
184204
}

0 commit comments

Comments
 (0)