mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
[dev] worker properties change from powerjob.xxx to powerjob.worker.xxx & If serverAddress is not exist, it will not start PowerJob worker
This commit is contained in:
parent
1ab8997c24
commit
76ed28003f
@ -4,10 +4,10 @@ spring.jpa.open-in-view=false
|
|||||||
|
|
||||||
########### powerjob-worker 配置 ###########
|
########### powerjob-worker 配置 ###########
|
||||||
# akka 工作端口,可选,默认 27777
|
# akka 工作端口,可选,默认 27777
|
||||||
powerjob.akka-port=27777
|
powerjob.worker.akka-port=27777
|
||||||
# 接入应用名称,用于分组隔离,推荐填写 本 Java 项目名称
|
# 接入应用名称,用于分组隔离,推荐填写 本 Java 项目名称
|
||||||
powerjob.app-name=powerjob-agent-test
|
powerjob.worker.app-name=powerjob-agent-test
|
||||||
# 调度服务器地址,IP:Port 或 域名,多值逗号分隔
|
# 调度服务器地址,IP:Port 或 域名,多值逗号分隔
|
||||||
powerjob.server-address=127.0.0.1:7700,127.0.0.1:7701
|
powerjob.worker.server-address=127.0.0.1:7700,127.0.0.1:7701
|
||||||
# 持久化方式,可选,默认 disk
|
# 持久化方式,可选,默认 disk
|
||||||
powerjob.store-strategy=disk
|
powerjob.worker.store-strategy=disk
|
@ -3,9 +3,12 @@ package com.github.kfcfans.powerjob.worker.autoconfigure;
|
|||||||
import com.github.kfcfans.powerjob.common.utils.CommonUtils;
|
import com.github.kfcfans.powerjob.common.utils.CommonUtils;
|
||||||
import com.github.kfcfans.powerjob.worker.OhMyWorker;
|
import com.github.kfcfans.powerjob.worker.OhMyWorker;
|
||||||
import com.github.kfcfans.powerjob.worker.common.OhMyConfig;
|
import com.github.kfcfans.powerjob.worker.common.OhMyConfig;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Conditional;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -19,32 +22,53 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties(PowerJobProperties.class)
|
@EnableConfigurationProperties(PowerJobProperties.class)
|
||||||
|
@Conditional(PowerJobAutoConfiguration.PowerJobWorkerCondition.class)
|
||||||
public class PowerJobAutoConfiguration {
|
public class PowerJobAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public OhMyWorker initPowerJob(PowerJobProperties properties) {
|
public OhMyWorker initPowerJob(PowerJobProperties properties) {
|
||||||
|
|
||||||
|
PowerJobProperties.Worker worker = properties.getWorker();
|
||||||
|
|
||||||
// 服务器HTTP地址(端口号为 server.port,而不是 ActorSystem port),请勿添加任何前缀(http://)
|
// 服务器HTTP地址(端口号为 server.port,而不是 ActorSystem port),请勿添加任何前缀(http://)
|
||||||
CommonUtils.requireNonNull(properties.getServerAddress(), "serverAddress can't be empty!");
|
CommonUtils.requireNonNull(worker.getServerAddress(), "serverAddress can't be empty!");
|
||||||
List<String> serverAddress = Arrays.asList(properties.getServerAddress().split(","));
|
List<String> serverAddress = Arrays.asList(worker.getServerAddress().split(","));
|
||||||
|
|
||||||
// 1. 创建配置文件
|
// 1. 创建配置文件
|
||||||
OhMyConfig config = new OhMyConfig();
|
OhMyConfig config = new OhMyConfig();
|
||||||
// 可以不显式设置,默认值 27777
|
// 可以不显式设置,默认值 27777
|
||||||
config.setPort(properties.getAkkaPort());
|
config.setPort(worker.getAkkaPort());
|
||||||
// appName,需要提前在控制台注册,否则启动报错
|
// appName,需要提前在控制台注册,否则启动报错
|
||||||
config.setAppName(properties.getAppName());
|
config.setAppName(worker.getAppName());
|
||||||
config.setServerAddress(serverAddress);
|
config.setServerAddress(serverAddress);
|
||||||
// 如果没有大型 Map/MapReduce 的需求,建议使用内存来加速计算
|
// 如果没有大型 Map/MapReduce 的需求,建议使用内存来加速计算
|
||||||
// 有大型 Map/MapReduce 需求,可能产生大量子任务(Task)的场景,请使用 DISK,否则妥妥的 OutOfMemory
|
// 有大型 Map/MapReduce 需求,可能产生大量子任务(Task)的场景,请使用 DISK,否则妥妥的 OutOfMemory
|
||||||
config.setStoreStrategy(properties.getStoreStrategy());
|
config.setStoreStrategy(worker.getStoreStrategy());
|
||||||
// 启动测试模式,true情况下,不再尝试连接 server 并验证appName
|
// 启动测试模式,true情况下,不再尝试连接 server 并验证appName
|
||||||
config.setEnableTestMode(properties.isEnableTestMode());
|
config.setEnableTestMode(worker.isEnableTestMode());
|
||||||
|
|
||||||
// 2. 创建 Worker 对象,设置配置文件
|
// 2. 创建 Worker 对象,设置配置文件
|
||||||
OhMyWorker ohMyWorker = new OhMyWorker();
|
OhMyWorker ohMyWorker = new OhMyWorker();
|
||||||
ohMyWorker.setConfig(config);
|
ohMyWorker.setConfig(config);
|
||||||
return ohMyWorker;
|
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 {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,10 @@ package com.github.kfcfans.powerjob.worker.autoconfigure;
|
|||||||
import com.github.kfcfans.powerjob.common.RemoteConstant;
|
import com.github.kfcfans.powerjob.common.RemoteConstant;
|
||||||
import com.github.kfcfans.powerjob.worker.common.constants.StoreStrategy;
|
import com.github.kfcfans.powerjob.worker.common.constants.StoreStrategy;
|
||||||
import com.github.kfcfans.powerjob.worker.core.processor.ProcessResult;
|
import com.github.kfcfans.powerjob.worker.core.processor.ProcessResult;
|
||||||
import lombok.Data;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PowerJob 配置项
|
* PowerJob 配置项
|
||||||
@ -12,33 +14,114 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||||||
* @author songyinyin
|
* @author songyinyin
|
||||||
* @since 2020/7/26 16:37
|
* @since 2020/7/26 16:37
|
||||||
*/
|
*/
|
||||||
@Data
|
|
||||||
@ConfigurationProperties(prefix = "powerjob")
|
@ConfigurationProperties(prefix = "powerjob")
|
||||||
public class PowerJobProperties {
|
public class PowerJobProperties {
|
||||||
|
|
||||||
|
private final Worker worker = new Worker();
|
||||||
|
|
||||||
|
public Worker getWorker() {
|
||||||
|
return worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@DeprecatedConfigurationProperty(replacement = "powerjob.worker.app-name")
|
||||||
|
public String getAppName() {
|
||||||
|
return getWorker().appName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void setAppName(String appName) {
|
||||||
|
getWorker().setAppName(appName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@DeprecatedConfigurationProperty(replacement = "powerjob.worker.akka-port")
|
||||||
|
public int getAkkaPort() {
|
||||||
|
return getWorker().akkaPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void setAkkaPort(int akkaPort) {
|
||||||
|
getWorker().setAkkaPort(akkaPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@DeprecatedConfigurationProperty(replacement = "powerjob.worker.server-address")
|
||||||
|
public String getServerAddress() {
|
||||||
|
return getWorker().serverAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void setServerAddress(String serverAddress) {
|
||||||
|
getWorker().setServerAddress(serverAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@DeprecatedConfigurationProperty(replacement = "powerjob.worker.store-strategy")
|
||||||
|
public StoreStrategy getStoreStrategy() {
|
||||||
|
return getWorker().storeStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void setStoreStrategy(StoreStrategy storeStrategy) {
|
||||||
|
getWorker().setStoreStrategy(storeStrategy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@DeprecatedConfigurationProperty(replacement = "powerjob.worker.max-result-length")
|
||||||
|
public int getMaxResultLength() {
|
||||||
|
return getWorker().maxResultLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void setMaxResultLength(int maxResultLength) {
|
||||||
|
getWorker().setMaxResultLength(maxResultLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@DeprecatedConfigurationProperty(replacement = "powerjob.worker.enable-test-mode")
|
||||||
|
public boolean isEnableTestMode() {
|
||||||
|
return getWorker().enableTestMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void setEnableTestMode(boolean enableTestMode) {
|
||||||
|
getWorker().setEnableTestMode(enableTestMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 应用名称,需要提前在控制台注册,否则启动报错
|
* 客户端 配置项
|
||||||
*/
|
*/
|
||||||
private String appName;
|
@Setter
|
||||||
/**
|
@Getter
|
||||||
* 启动 akka 端口
|
public static class Worker {
|
||||||
*/
|
/**
|
||||||
private int akkaPort = RemoteConstant.DEFAULT_WORKER_PORT;
|
* 应用名称,需要提前在控制台注册,否则启动报错
|
||||||
/**
|
*/
|
||||||
* 调度服务器地址,ip:port 或 域名,多个用英文逗号分隔
|
private String appName;
|
||||||
*/
|
/**
|
||||||
private String serverAddress;
|
* 启动 akka 端口
|
||||||
/**
|
*/
|
||||||
* 本地持久化方式,默认使用磁盘
|
private int akkaPort = RemoteConstant.DEFAULT_WORKER_PORT;
|
||||||
*/
|
/**
|
||||||
private StoreStrategy storeStrategy = StoreStrategy.DISK;
|
* 调度服务器地址,ip:port 或 域名,多个用英文逗号分隔
|
||||||
/**
|
*/
|
||||||
* 最大返回值长度,超过会被截断
|
private String serverAddress;
|
||||||
* {@link ProcessResult}#msg 的最大长度
|
/**
|
||||||
*/
|
* 本地持久化方式,默认使用磁盘
|
||||||
private int maxResultLength = 8096;
|
*/
|
||||||
/**
|
private StoreStrategy storeStrategy = StoreStrategy.DISK;
|
||||||
* 启动测试模式,true情况下,不再尝试连接 server 并验证appName。
|
/**
|
||||||
* true -> 用于本地写单元测试调试; false -> 默认值,标准模式
|
* 最大返回值长度,超过会被截断
|
||||||
*/
|
* {@link ProcessResult}#msg 的最大长度
|
||||||
private boolean enableTestMode = false;
|
*/
|
||||||
|
private int maxResultLength = 8096;
|
||||||
|
/**
|
||||||
|
* 启动测试模式,true情况下,不再尝试连接 server 并验证appName。
|
||||||
|
* true -> 用于本地写单元测试调试; false -> 默认值,标准模式
|
||||||
|
*/
|
||||||
|
private boolean enableTestMode = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,46 +4,106 @@
|
|||||||
"name": "powerjob",
|
"name": "powerjob",
|
||||||
"type": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
"type": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties"
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "powerjob.worker",
|
||||||
|
"type": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties$Worker",
|
||||||
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||||
|
"sourceMethod": "getWorker()"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"properties": [
|
"properties": [
|
||||||
{
|
{
|
||||||
"name": "powerjob.app-name",
|
"name": "powerjob.worker.akka-port",
|
||||||
"type": "java.lang.String",
|
"type": "java.lang.Integer",
|
||||||
"description": "应用名称,需要提前在控制台注册,否则启动报错",
|
"description": "启动 akka 端口",
|
||||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties"
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties$Worker"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "powerjob.max-result-length",
|
"name": "powerjob.worker.app-name",
|
||||||
|
"type": "java.lang.String",
|
||||||
|
"description": "应用名称,需要提前在控制台注册,否则启动报错",
|
||||||
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties$Worker"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "powerjob.worker.enable-test-mode",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "启动测试模式,true情况下,不再尝试连接 server 并验证appName。 true -> 用于本地写单元测试调试; false -> 默认值,标准模式",
|
||||||
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties$Worker",
|
||||||
|
"defaultValue": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "powerjob.worker.max-result-length",
|
||||||
"type": "java.lang.Integer",
|
"type": "java.lang.Integer",
|
||||||
"description": "最大返回值长度,超过会被截断 {@link ProcessResult}#msg 的最大长度",
|
"description": "最大返回值长度,超过会被截断 {@link ProcessResult}#msg 的最大长度",
|
||||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties$Worker",
|
||||||
"defaultValue": 8096
|
"defaultValue": 8096
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "powerjob.worker.server-address",
|
||||||
|
"type": "java.lang.String",
|
||||||
|
"description": "调度服务器地址,ip:port 或 域名,多个用英文逗号分隔",
|
||||||
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties$Worker"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "powerjob.worker.store-strategy",
|
||||||
|
"type": "com.github.kfcfans.powerjob.worker.common.constants.StoreStrategy",
|
||||||
|
"description": "本地持久化方式,默认使用磁盘",
|
||||||
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties$Worker"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "powerjob.akka-port",
|
"name": "powerjob.akka-port",
|
||||||
"type": "java.lang.Integer",
|
"type": "java.lang.Integer",
|
||||||
"description": "启动 akka 端口",
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties"
|
"deprecated": true,
|
||||||
|
"deprecation": {
|
||||||
|
"replacement": "powerjob.worker.akka-port"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "powerjob.server-address",
|
"name": "powerjob.app-name",
|
||||||
"type": "java.lang.String",
|
"type": "java.lang.String",
|
||||||
"description": "调度服务器地址,ip:port 或 域名,多值用英文逗号分隔",
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties"
|
"deprecated": true,
|
||||||
},
|
"deprecation": {
|
||||||
{
|
"replacement": "powerjob.worker.app-name"
|
||||||
"name": "powerjob.store-strategy",
|
}
|
||||||
"type": "com.github.kfcfans.powerjob.worker.common.constants.StoreStrategy",
|
|
||||||
"description": "本地持久化方式,默认使用磁盘",
|
|
||||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "powerjob.enable-test-mode",
|
"name": "powerjob.enable-test-mode",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"description": "启动测试模式,true情况下,不再尝试连接 server 并验证appName。true -> 用于本地写单元测试调试; false -> 默认值,标准模式",
|
|
||||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||||
"defaultValue": false
|
"deprecated": true,
|
||||||
|
"deprecation": {
|
||||||
|
"replacement": "powerjob.worker.enable-test-mode"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "powerjob.max-result-length",
|
||||||
|
"type": "java.lang.Integer",
|
||||||
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||||
|
"deprecated": true,
|
||||||
|
"deprecation": {
|
||||||
|
"replacement": "powerjob.worker.max-result-length"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "powerjob.server-address",
|
||||||
|
"type": "java.lang.String",
|
||||||
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||||
|
"deprecated": true,
|
||||||
|
"deprecation": {
|
||||||
|
"replacement": "powerjob.worker.server-address"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "powerjob.store-strategy",
|
||||||
|
"type": "com.github.kfcfans.powerjob.worker.common.constants.StoreStrategy",
|
||||||
|
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||||
|
"deprecated": true,
|
||||||
|
"deprecation": {
|
||||||
|
"replacement": "powerjob.worker.store-strategy"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"hints": []
|
"hints": []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user