feat: support lazy init#725

This commit is contained in:
tjq 2023-09-02 13:19:15 +08:00
parent a138f9c8cc
commit c875ba3d37
5 changed files with 14 additions and 14 deletions

View File

@ -4,7 +4,7 @@ spring.jpa.open-in-view=false
# Whether to enable PowerJob Worker, default is true
powerjob.worker.enabled=true
# Turn on test mode and do not force the server connection to be verified
powerjob.worker.enable-test-mode=false
powerjob.worker.allow-lazy-connect-server=false
# Transport port, default is 27777
powerjob.worker.port=27777
# Application name, used for grouping applications. Recommend to set the same value as project name.

View File

@ -72,7 +72,7 @@ public class PowerJobAutoConfiguration {
* When enabledTestMode is set as true, PowerJob-worker no longer connects to PowerJob-server
* or validate appName.
*/
config.setEnableTestMode(worker.isEnableTestMode());
config.setAllowLazyConnectServer(worker.isAllowLazyConnectServer());
/*
* Max length of appended workflow context . Appended workflow context value that is longer than the value will be ignored.
*/

View File

@ -81,14 +81,14 @@ public class PowerJobProperties {
}
@Deprecated
@DeprecatedConfigurationProperty(replacement = "powerjob.worker.enable-test-mode")
@DeprecatedConfigurationProperty(replacement = "powerjob.worker.allow-lazy-connect-server")
public boolean isEnableTestMode() {
return getWorker().enableTestMode;
return getWorker().isAllowLazyConnectServer();
}
@Deprecated
public void setEnableTestMode(boolean enableTestMode) {
getWorker().setEnableTestMode(enableTestMode);
getWorker().setAllowLazyConnectServer(enableTestMode);
}
/**
@ -146,10 +146,10 @@ public class PowerJobProperties {
*/
private int maxResultLength = 8192;
/**
* If test mode is set as true, Powerjob-worker no longer connects to the server or validates appName.
* Test mode is used for conditions that your have no powerjob-server in your develop env, so you can't start up the application
* If allowLazyConnectServer is set as true, PowerJob worker allows launching without a direct connection to the server.
* allowLazyConnectServer is used for conditions that your have no powerjob-server in your develop env so you can't startup the application
*/
private boolean enableTestMode = false;
private boolean allowLazyConnectServer = false;
/**
* Max length of appended workflow context value length. Appended workflow context value that is longer than the value will be ignored.
* {@link WorkflowContext} max length for #appendedContextData

View File

@ -65,8 +65,8 @@ public class PowerJobServerDiscoveryService implements ServerDiscoveryService {
try {
return assertApp0();
} catch (Exception e) {
if (config.isEnableTestMode()) {
log.warn("[PowerJobWorker] using TestMode now, it's dangerous if this is production env.");
if (config.isAllowLazyConnectServer()) {
log.warn("[PowerJobWorker] worker is not currently connected to the server, and because allowLazyConnectServer is configured to true it won't block the startup, but you have to be aware that this is dangerous in production environments!");
// 返回引用方便后续更新对象内属性
return appInfo;
@ -123,7 +123,7 @@ public class PowerJobServerDiscoveryService implements ServerDiscoveryService {
@Override
public void timingCheck(ScheduledExecutorService timingPool) {
this.currentServerAddress = discovery();
if (StringUtils.isEmpty(this.currentServerAddress) && !config.isEnableTestMode()) {
if (StringUtils.isEmpty(this.currentServerAddress) && !config.isAllowLazyConnectServer()) {
throw new PowerJobException("can't find any available server, this worker has been quarantined.");
}
// 这里必须保证成功

View File

@ -57,10 +57,10 @@ public class PowerJobWorkerConfig {
*/
private StoreStrategy storeStrategy = StoreStrategy.DISK;
/**
* If test mode is set as true, Powerjob-worker no longer connects to the server or validates appName.
* Test mode is used for conditions that your have no powerjob-server in your develop env so you can't startup the application
* If allowLazyConnectServer is set as true, PowerJob worker allows launching without a direct connection to the server.
* allowLazyConnectServer is used for conditions that your have no powerjob-server in your develop env so you can't startup the application
*/
private boolean enableTestMode = false;
private boolean allowLazyConnectServer = false;
/**
* Max length of appended workflow context value length. Appended workflow context value that is longer than the value will be ignore.
* {@link WorkflowContext} max length for #appendedContextData