优化
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.baiyue.common.web;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/** Enables scheduled workers by default while allowing blue-green web slots to disable them. */
|
||||
@AutoConfiguration
|
||||
@EnableScheduling
|
||||
@ConditionalOnProperty(prefix = "baiyue.runtime", name = "scheduling-enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
public class BaiyueSchedulingAutoConfiguration {
|
||||
}
|
||||
+1
@@ -2,3 +2,4 @@ com.baiyue.common.web.LongIdJacksonConfiguration
|
||||
com.baiyue.common.web.CommonWebAutoConfiguration
|
||||
com.baiyue.common.web.FeignTracePropagationAutoConfiguration
|
||||
com.baiyue.common.web.RestClientTracePropagationAutoConfiguration
|
||||
com.baiyue.common.web.BaiyueSchedulingAutoConfiguration
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.baiyue.common.web;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.scheduling.config.TaskManagementConfigUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class BaiyueSchedulingAutoConfigurationTest {
|
||||
private final ApplicationContextRunner runner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(BaiyueSchedulingAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
void schedulingIsEnabledByDefault() {
|
||||
runner.run(context -> assertThat(context)
|
||||
.hasBean(TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
void blueGreenWebSlotCanDisableScheduling() {
|
||||
runner.withPropertyValues("baiyue.runtime.scheduling-enabled=false")
|
||||
.run(context -> assertThat(context)
|
||||
.doesNotHaveBean(TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user