Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c875ba3

Browse files
committed
feat: support lazy init#725
1 parent a138f9c commit c875ba3

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

powerjob-worker-samples/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ spring.jpa.open-in-view=false
44
# Whether to enable PowerJob Worker, default is true
55
powerjob.worker.enabled=true
66
# Turn on test mode and do not force the server connection to be verified
7-
powerjob.worker.enable-test-mode=false
7+
powerjob.worker.allow-lazy-connect-server=false
88
# Transport port, default is 27777
99
powerjob.worker.port=27777
1010
# Application name, used for grouping applications. Recommend to set the same value as project name.

powerjob-worker-spring-boot-starter/src/main/java/tech/powerjob/worker/autoconfigure/PowerJobAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public PowerJobSpringWorker initPowerJob(PowerJobProperties properties) {
7272
* When enabledTestMode is set as true, PowerJob-worker no longer connects to PowerJob-server
7373
* or validate appName.
7474
*/
75-
config.setEnableTestMode(worker.isEnableTestMode());
75+
config.setAllowLazyConnectServer(worker.isAllowLazyConnectServer());
7676
/*
7777
* Max length of appended workflow context . Appended workflow context value that is longer than the value will be ignored.
7878
*/

powerjob-worker-spring-boot-starter/src/main/java/tech/powerjob/worker/autoconfigure/PowerJobProperties.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ public void setMaxResultLength(int maxResultLength) {
8181
}
8282

8383
@Deprecated
84-
@DeprecatedConfigurationProperty(replacement = "powerjob.worker.enable-test-mode")
84+
@DeprecatedConfigurationProperty(replacement = "powerjob.worker.allow-lazy-connect-server")
8585
public boolean isEnableTestMode() {
86-
return getWorker().enableTestMode;
86+
return getWorker().isAllowLazyConnectServer();
8787
}
8888

8989
@Deprecated
9090
public void setEnableTestMode(boolean enableTestMode) {
91-
getWorker().setEnableTestMode(enableTestMode);
91+
getWorker().setAllowLazyConnectServer(enableTestMode);
9292
}
9393

9494
/**
@@ -146,10 +146,10 @@ public static class Worker {
146146
*/
147147
private int maxResultLength = 8192;
148148
/**
149-
* If test mode is set as true, Powerjob-worker no longer connects to the server or validates appName.
150-
* Test mode is used for conditions that your have no powerjob-server in your develop env, so you can't start up the application
149+
* If allowLazyConnectServer is set as true, PowerJob worker allows launching without a direct connection to the server.
150+
* allowLazyConnectServer is used for conditions that your have no powerjob-server in your develop env so you can't startup the application
151151
*/
152-
private boolean enableTestMode = false;
152+
private boolean allowLazyConnectServer = false;
153153
/**
154154
* Max length of appended workflow context value length. Appended workflow context value that is longer than the value will be ignored.
155155
* {@link WorkflowContext} max length for #appendedContextData

powerjob-worker/src/main/java/tech/powerjob/worker/background/discovery/PowerJobServerDiscoveryService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public AppInfo assertApp() {
6565
try {
6666
return assertApp0();
6767
} catch (Exception e) {
68-
if (config.isEnableTestMode()) {
69-
log.warn("[PowerJobWorker] using TestMode now, it's dangerous if this is production env.");
68+
if (config.isAllowLazyConnectServer()) {
69+
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!");
7070

7171
// 返回引用,方便后续更新对象内属性
7272
return appInfo;
@@ -123,7 +123,7 @@ public String getCurrentServerAddress() {
123123
@Override
124124
public void timingCheck(ScheduledExecutorService timingPool) {
125125
this.currentServerAddress = discovery();
126-
if (StringUtils.isEmpty(this.currentServerAddress) && !config.isEnableTestMode()) {
126+
if (StringUtils.isEmpty(this.currentServerAddress) && !config.isAllowLazyConnectServer()) {
127127
throw new PowerJobException("can't find any available server, this worker has been quarantined.");
128128
}
129129
// 这里必须保证成功

powerjob-worker/src/main/java/tech/powerjob/worker/common/PowerJobWorkerConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ public class PowerJobWorkerConfig {
5757
*/
5858
private StoreStrategy storeStrategy = StoreStrategy.DISK;
5959
/**
60-
* If test mode is set as true, Powerjob-worker no longer connects to the server or validates appName.
61-
* Test mode is used for conditions that your have no powerjob-server in your develop env so you can't startup the application
60+
* If allowLazyConnectServer is set as true, PowerJob worker allows launching without a direct connection to the server.
61+
* allowLazyConnectServer is used for conditions that your have no powerjob-server in your develop env so you can't startup the application
6262
*/
63-
private boolean enableTestMode = false;
63+
private boolean allowLazyConnectServer = false;
6464
/**
6565
* Max length of appended workflow context value length. Appended workflow context value that is longer than the value will be ignore.
6666
* {@link WorkflowContext} max length for #appendedContextData

0 commit comments

Comments
 (0)