From 88bc28140ff4a35675bfcba2a4af166a82bb2887 Mon Sep 17 00:00:00 2001 From: songyinyin Date: Wed, 7 Sep 2022 23:44:36 +0800 Subject: [PATCH] feat: powerjob worker add property: powerjob.worker.enabled --- .../config/SqlProcessorConfiguration.java | 3 + .../src/main/resources/application.properties | 2 + powerjob-worker-spring-boot-starter/pom.xml | 7 ++ .../PowerJobAutoConfiguration.java | 34 +++------- .../autoconfigure/PowerJobProperties.java | 6 ++ .../spring-configuration-metadata.json | 68 ------------------- 6 files changed, 26 insertions(+), 94 deletions(-) delete mode 100644 powerjob-worker-spring-boot-starter/src/main/resources/META-INF/spring-configuration-metadata.json diff --git a/powerjob-worker-samples/src/main/java/tech/powerjob/samples/config/SqlProcessorConfiguration.java b/powerjob-worker-samples/src/main/java/tech/powerjob/samples/config/SqlProcessorConfiguration.java index 59211ac9..9c5b7332 100644 --- a/powerjob-worker-samples/src/main/java/tech/powerjob/samples/config/SqlProcessorConfiguration.java +++ b/powerjob-worker-samples/src/main/java/tech/powerjob/samples/config/SqlProcessorConfiguration.java @@ -1,5 +1,6 @@ package tech.powerjob.samples.config; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import tech.powerjob.common.utils.CommonUtils; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; @@ -9,6 +10,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; import tech.powerjob.official.processors.impl.sql.SpringDatasourceSqlProcessor; +import tech.powerjob.worker.PowerJobWorker; import javax.sql.DataSource; @@ -17,6 +19,7 @@ import javax.sql.DataSource; * @since 2021/3/10 */ @Configuration +@ConditionalOnBean(PowerJobWorker.class) public class SqlProcessorConfiguration { diff --git a/powerjob-worker-samples/src/main/resources/application.properties b/powerjob-worker-samples/src/main/resources/application.properties index b303af55..ea139d9c 100644 --- a/powerjob-worker-samples/src/main/resources/application.properties +++ b/powerjob-worker-samples/src/main/resources/application.properties @@ -1,6 +1,8 @@ server.port=8081 spring.jpa.open-in-view=false ########### PowerJob-worker properties. ########### +# Whether to enable PowerJob Worker, default is true +powerjob.worker.enabled=true # Akka port, default is 27777 powerjob.worker.akka-port=27777 # Application name, used for grouping applications. Recommend to set the same value as project name. diff --git a/powerjob-worker-spring-boot-starter/pom.xml b/powerjob-worker-spring-boot-starter/pom.xml index a35680fa..961bce08 100644 --- a/powerjob-worker-spring-boot-starter/pom.xml +++ b/powerjob-worker-spring-boot-starter/pom.xml @@ -33,6 +33,13 @@ compile + + org.springframework.boot + spring-boot-configuration-processor + ${springboot.version} + true + + org.springframework.boot spring-boot-starter-test diff --git a/powerjob-worker-spring-boot-starter/src/main/java/tech/powerjob/worker/autoconfigure/PowerJobAutoConfiguration.java b/powerjob-worker-spring-boot-starter/src/main/java/tech/powerjob/worker/autoconfigure/PowerJobAutoConfiguration.java index c8673b9b..ccd1617f 100644 --- a/powerjob-worker-spring-boot-starter/src/main/java/tech/powerjob/worker/autoconfigure/PowerJobAutoConfiguration.java +++ b/powerjob-worker-spring-boot-starter/src/main/java/tech/powerjob/worker/autoconfigure/PowerJobAutoConfiguration.java @@ -1,29 +1,27 @@ package tech.powerjob.worker.autoconfigure; -import tech.powerjob.common.utils.CommonUtils; -import tech.powerjob.common.utils.NetUtils; -import tech.powerjob.worker.PowerJobWorker; -import tech.powerjob.worker.common.PowerJobWorkerConfig; -import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; +import tech.powerjob.common.utils.CommonUtils; +import tech.powerjob.common.utils.NetUtils; +import tech.powerjob.worker.PowerJobWorker; +import tech.powerjob.worker.common.PowerJobWorkerConfig; import java.util.Arrays; import java.util.List; /** - * Auto configuration class for PowerJob-worker. + * Autoconfiguration class for PowerJob-worker. * * @author songyinyin * @since 2020/7/26 16:37 */ @Configuration @EnableConfigurationProperties(PowerJobProperties.class) -@Conditional(PowerJobAutoConfiguration.PowerJobWorkerCondition.class) +@ConditionalOnProperty(prefix = "powerjob.worker", name = "enabled", havingValue = "true", matchIfMissing = true) public class PowerJobAutoConfiguration { @Bean @@ -36,7 +34,8 @@ public class PowerJobAutoConfiguration { * Address of PowerJob-server node(s). Do not mistake for ActorSystem port. Do not add * any prefix, i.e. http://. */ - CommonUtils.requireNonNull(worker.getServerAddress(), "serverAddress can't be empty!"); + CommonUtils.requireNonNull(worker.getServerAddress(), "serverAddress can't be empty! " + + "if you don't want to enable powerjob, please config program arguments: powerjob.worker.enabled=false"); List serverAddress = Arrays.asList(worker.getServerAddress().split(",")); /* @@ -85,21 +84,4 @@ public class PowerJobAutoConfiguration { return ohMyWorker; } - static class PowerJobWorkerCondition extends AnyNestedCondition { - - public PowerJobWorkerCondition() { - super(ConfigurationPhase.PARSE_CONFIGURATION); - } - - @Deprecated - @ConditionalOnProperty(prefix = "powerjob", name = "server-address") - static class PowerJobProperty { - - } - - @ConditionalOnProperty(prefix = "powerjob.worker", name = "server-address") - static class PowerJobWorkerProperty { - - } - } } diff --git a/powerjob-worker-spring-boot-starter/src/main/java/tech/powerjob/worker/autoconfigure/PowerJobProperties.java b/powerjob-worker-spring-boot-starter/src/main/java/tech/powerjob/worker/autoconfigure/PowerJobProperties.java index b9b19461..d58f86d1 100644 --- a/powerjob-worker-spring-boot-starter/src/main/java/tech/powerjob/worker/autoconfigure/PowerJobProperties.java +++ b/powerjob-worker-spring-boot-starter/src/main/java/tech/powerjob/worker/autoconfigure/PowerJobProperties.java @@ -107,6 +107,12 @@ public class PowerJobProperties { @Setter @Getter public static class Worker { + + /** + * Whether to enable PowerJob Worker + */ + private boolean enabled = true; + /** * Name of application, String type. Total length of this property should be no more than 255 * characters. This is one of the required properties when registering a new application. This diff --git a/powerjob-worker-spring-boot-starter/src/main/resources/META-INF/spring-configuration-metadata.json b/powerjob-worker-spring-boot-starter/src/main/resources/META-INF/spring-configuration-metadata.json deleted file mode 100644 index e2daf190..00000000 --- a/powerjob-worker-spring-boot-starter/src/main/resources/META-INF/spring-configuration-metadata.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "groups": [ - { - "name": "powerjob", - "type": "tech.powerjob.worker.autoconfigure.PowerJobProperties", - "sourceType": "tech.powerjob.worker.autoconfigure.PowerJobProperties" - }, - { - "name": "powerjob.worker", - "type": "tech.powerjob.worker.autoconfigure.PowerJobProperties$Worker", - "sourceType": "tech.powerjob.worker.autoconfigure.PowerJobProperties", - "sourceMethod": "getWorker()" - } - ], - "properties": [ - { - "name": "powerjob.worker.akka-port", - "type": "java.lang.Integer", - "description": "Akka port of PowerJob-worker", - "sourceType": "tech.powerjob.worker.autoconfigure.PowerJobProperties$Worker" - }, - { - "name": "powerjob.worker.app-name", - "type": "java.lang.String", - "description": "Name of application. Register in PowerJob-console to prevent error.", - "sourceType": "tech.powerjob.worker.autoconfigure.PowerJobProperties$Worker" - }, - { - "name": "powerjob.worker.enable-test-mode", - "type": "java.lang.Boolean", - "description": "Whether to enable test mode. In test mode, worker will not connect to server.", - "sourceType": "tech.powerjob.worker.autoconfigure.PowerJobProperties$Worker", - "defaultValue": false - }, - { - "name": "powerjob.worker.max-result-length", - "type": "java.lang.Integer", - "description": "Max length for {@link ProcessResult}#msg, result longer than this property will be truncated.", - "sourceType": "tech.powerjob.worker.autoconfigure.PowerJobProperties$Worker", - "defaultValue": 8096 - }, - { - "name": "powerjob.worker.server-address", - "type": "java.lang.String", - "description": "PowerJob-server node(s) address. Ip:port or domain, multiple addresses should be separated with comma", - "sourceType": "tech.powerjob.worker.autoconfigure.PowerJobProperties$Worker" - }, - { - "name": "powerjob.worker.store-strategy", - "type": "tech.powerjob.worker.common.constants.StoreStrategy", - "description": "Local store strategy, disk or memory", - "sourceType": "tech.powerjob.worker.autoconfigure.PowerJobProperties$Worker" - }, - { - "name": "powerjob.worker.max-appended-wf-context-length", - "type": "java.lang.Integer", - "description": "Max length of appended workflow context. Appended workflow context that is longer than the value will be ignore.", - "sourceType": "tech.powerjob.worker.autoconfigure.PowerJobProperties$Worker" - }, - { - "name": "powerjob.worker.tag", - "type": "java.lang.String", - "description": "Worker Tag", - "sourceType": "tech.powerjob.worker.autoconfigure.PowerJobProperties$Worker" - } - ], - "hints": [] -} \ No newline at end of file