feat: powerjob worker add property: powerjob.worker.enabled

This commit is contained in:
songyinyin 2022-09-07 23:44:36 +08:00
parent ad1a7227d6
commit 88bc28140f
6 changed files with 26 additions and 94 deletions

View File

@ -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 {

View File

@ -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.

View File

@ -33,6 +33,13 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${springboot.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@ -1,16 +1,14 @@
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;
@ -23,7 +21,7 @@ import java.util.List;
*/
@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<String> 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 {
}
}
}

View File

@ -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

View File

@ -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": []
}