---初始化项目

This commit is contained in:
2025-09-19 16:14:08 +08:00
parent 902d3d7e3b
commit afee7c03ac
767 changed files with 75809 additions and 82 deletions

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>powerjob</artifactId>
<groupId>tech.powerjob</groupId>
<version>5.1.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-worker-spring-boot-starter</artifactId>
<name>powerjob-worker-spring-boot-starter</name>
<version>5.1.2</version>
<packaging>jar</packaging>
<properties>
<powerjob.worker.version>5.1.2</powerjob.worker.version>
<springboot.version>2.7.18</springboot.version>
</properties>
<dependencies>
<!-- oms-worker -->
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-worker</artifactId>
<version>${powerjob.worker.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${springboot.version}</version>
<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>
<version>${springboot.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,94 @@
package tech.powerjob.worker.autoconfigure;
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.Configuration;
import tech.powerjob.common.utils.CommonUtils;
import tech.powerjob.common.utils.NetUtils;
import tech.powerjob.worker.PowerJobSpringWorker;
import tech.powerjob.worker.common.PowerJobWorkerConfig;
import java.util.Arrays;
import java.util.List;
/**
* Autoconfiguration class for PowerJob-worker.
*
* @author songyinyin
* @since 2020/7/26 16:37
*/
@Configuration
@EnableConfigurationProperties(PowerJobProperties.class)
@ConditionalOnProperty(prefix = "powerjob.worker", name = "enabled", havingValue = "true", matchIfMissing = true)
public class PowerJobAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public PowerJobSpringWorker initPowerJob(PowerJobProperties properties) {
PowerJobProperties.Worker worker = properties.getWorker();
/*
* 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! " +
"if you don't want to enable powerjob, please config program arguments: powerjob.worker.enabled=false");
List<String> serverAddress = Arrays.asList(worker.getServerAddress().split(","));
/*
* Create OhMyConfig object for setting properties.
*/
PowerJobWorkerConfig config = new PowerJobWorkerConfig();
/*
* Configuration of worker port. Random port is enabled when port is set with non-positive number.
*/
if (worker.getPort() != null) {
config.setPort(worker.getPort());
} else {
int port = worker.getAkkaPort();
if (port <= 0) {
port = NetUtils.getRandomPort();
}
config.setPort(port);
}
/*
* appName, name of the application. Applications should be registered in advance to prevent
* error. This property should be the same with what you entered for appName when getting
* registered.
*/
config.setAppName(worker.getAppName());
config.setServerAddress(serverAddress);
config.setProtocol(worker.getProtocol());
/*
* For non-Map/MapReduce tasks, {@code memory} is recommended for speeding up calculation.
* Map/MapReduce tasks may produce batches of subtasks, which could lead to OutOfMemory
* exception or error, {@code disk} should be applied.
*/
config.setStoreStrategy(worker.getStoreStrategy());
/*
* When enabledTestMode is set as true, PowerJob-worker no longer connects to PowerJob-server
* or validate appName.
*/
config.setAllowLazyConnectServer(worker.isAllowLazyConnectServer());
/*
* Max length of appended workflow context . Appended workflow context value that is longer than the value will be ignored.
*/
config.setMaxAppendedWfContextLength(worker.getMaxAppendedWfContextLength());
config.setTag(worker.getTag());
config.setMaxHeavyweightTaskNum(worker.getMaxHeavyweightTaskNum());
config.setMaxLightweightTaskNum(worker.getMaxLightweightTaskNum());
config.setHealthReportInterval(worker.getHealthReportInterval());
/*
* Create PowerJobSpringWorker object and set properties.
*/
return new PowerJobSpringWorker(config);
}
}

View File

@ -0,0 +1,174 @@
package tech.powerjob.worker.autoconfigure;
import tech.powerjob.common.RemoteConstant;
import tech.powerjob.common.enums.Protocol;
import tech.powerjob.worker.common.constants.StoreStrategy;
import tech.powerjob.worker.core.processor.ProcessResult;
import tech.powerjob.worker.core.processor.WorkflowContext;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
/**
* PowerJob properties configuration class.
*
* @author songyinyin
* @since 2020/7/26 16:37
*/
@ConfigurationProperties(prefix = "powerjob")
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.allow-lazy-connect-server")
public boolean isEnableTestMode() {
return getWorker().isAllowLazyConnectServer();
}
@Deprecated
public void setEnableTestMode(boolean enableTestMode) {
getWorker().setAllowLazyConnectServer(enableTestMode);
}
/**
* Powerjob worker configuration properties.
*/
@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
* property should be assigned with the same value as what you entered for the appName.
*/
private String appName;
/**
* Akka port of Powerjob-worker, optional value. Default value of this property is 27777.
* If multiple PowerJob-worker nodes were deployed, different, unique ports should be assigned.
* Deprecated, please use 'port'
*/
@Deprecated
private int akkaPort = RemoteConstant.DEFAULT_WORKER_PORT;
/**
* port
*/
private Integer port;
/**
* Address(es) of Powerjob-server node(s). Ip:port or domain.
* Example of single Powerjob-server node:
* <p>
* 127.0.0.1:7700
* </p>
* Example of Powerjob-server cluster:
* <p>
* 192.168.0.10:7700,192.168.0.11:7700,192.168.0.12:7700
* </p>
*/
private String serverAddress;
/**
* Protocol for communication between WORKER and server
*/
private Protocol protocol = Protocol.AKKA;
/**
* Local store strategy for H2 database. {@code disk} or {@code memory}.
*/
private StoreStrategy storeStrategy = StoreStrategy.DISK;
/**
* Max length of response result. Result that is longer than the value will be truncated.
* {@link ProcessResult} max length for #msg
*/
private int maxResultLength = 8192;
/**
* 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 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
*/
private int maxAppendedWfContextLength = 8192;
private String tag;
/**
* Max numbers of LightTaskTacker
*/
private Integer maxLightweightTaskNum = 1024;
/**
* Max numbers of HeavyTaskTacker
*/
private Integer maxHeavyweightTaskNum = 64;
/**
* Interval(s) of worker health report
*/
private Integer healthReportInterval = 10;
}
}

View File

@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
tech.powerjob.worker.autoconfigure.PowerJobAutoConfiguration

View File

@ -0,0 +1 @@
tech.powerjob.worker.autoconfigure.PowerJobAutoConfiguration

View File

@ -0,0 +1,22 @@
package tech.powerjob.worker.autoconfigure;
import tech.powerjob.worker.PowerJobWorker;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableAutoConfiguration
class PowerJobAutoConfigurationTest {
@Test
void testAutoConfiguration() {
ConfigurableApplicationContext run = SpringApplication.run(PowerJobAutoConfigurationTest.class);
PowerJobWorker worker = run.getBean(PowerJobWorker.class);
Assertions.assertNotNull(worker);
}
}

View File

@ -0,0 +1 @@
powerjob.enable-test-mode=true