|
23 | 23 | import com.netflix.genie.agent.utils.locks.impl.FileLockFactory;
|
24 | 24 | import com.netflix.genie.common.internal.util.GenieHostInfo;
|
25 | 25 | import com.netflix.genie.common.internal.util.HostnameUtil;
|
| 26 | +import org.springframework.beans.factory.config.BeanPostProcessor; |
26 | 27 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
| 28 | +import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration; |
27 | 29 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
28 |
| -import org.springframework.boot.task.TaskExecutorCustomizer; |
29 |
| -import org.springframework.boot.task.TaskSchedulerCustomizer; |
30 | 30 | import org.springframework.context.annotation.Bean;
|
31 | 31 | import org.springframework.context.annotation.Configuration;
|
32 | 32 | import org.springframework.context.annotation.Lazy;
|
|
51 | 51 | )
|
52 | 52 | public class AgentAutoConfiguration {
|
53 | 53 |
|
| 54 | + // Common bean names used by Spring Boot |
| 55 | + private static final String TASK_SCHEDULER_BEAN_NAME = "taskScheduler"; |
| 56 | + |
54 | 57 | /**
|
55 | 58 | * Provide a bean of type {@link GenieHostInfo} if none already exists.
|
56 | 59 | *
|
@@ -151,34 +154,51 @@ public TaskScheduler heartBeatServiceTaskScheduler(final AgentProperties agentPr
|
151 | 154 | }
|
152 | 155 |
|
153 | 156 | /**
|
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. |
155 | 159 | *
|
156 | 160 | * @param agentProperties the agent properties
|
157 |
| - * @return a customizer for the task executor |
| 161 | + * @return A BeanPostProcessor that customizes task executors |
158 | 162 | */
|
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 | + } |
166 | 177 | };
|
167 | 178 | }
|
168 | 179 |
|
169 | 180 | /**
|
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. |
171 | 183 | *
|
172 | 184 | * @param agentProperties the agent properties
|
173 |
| - * @return a customizer for the task scheduler |
| 185 | + * @return A BeanPostProcessor that customizes task schedulers |
174 | 186 | */
|
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 | + } |
182 | 202 | };
|
183 | 203 | }
|
184 | 204 | }
|
0 commit comments