mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
Merge branch '4.3.3'
This commit is contained in:
commit
df7ceb7ba5
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<artifactId>powerjob</artifactId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>powerjob</name>
|
||||
<url>http://www.powerjob.tech</url>
|
||||
|
@ -5,18 +5,18 @@
|
||||
<parent>
|
||||
<artifactId>powerjob</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>powerjob-client</artifactId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<junit.version>5.9.1</junit.version>
|
||||
<fastjson.version>1.2.83</fastjson.version>
|
||||
<powerjob.common.version>4.3.2</powerjob.common.version>
|
||||
<powerjob.common.version>4.3.3</powerjob.common.version>
|
||||
|
||||
<mvn.shade.plugin.version>3.2.4</mvn.shade.plugin.version>
|
||||
</properties>
|
||||
|
@ -5,12 +5,12 @@
|
||||
<parent>
|
||||
<artifactId>powerjob</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>powerjob-common</artifactId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
|
@ -5,12 +5,12 @@
|
||||
<parent>
|
||||
<artifactId>powerjob</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>powerjob-official-processors</artifactId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
@ -20,7 +20,7 @@
|
||||
<!-- 不会被打包的部分,scope 只能是 test 或 provide -->
|
||||
<junit.version>5.9.1</junit.version>
|
||||
<logback.version>1.2.9</logback.version>
|
||||
<powerjob.worker.version>4.3.2</powerjob.worker.version>
|
||||
<powerjob.worker.version>4.3.3</powerjob.worker.version>
|
||||
<spring.jdbc.version>5.2.9.RELEASE</spring.jdbc.version>
|
||||
<h2.db.version>2.1.214</h2.db.version>
|
||||
<mysql.version>8.0.28</mysql.version>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>powerjob</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>powerjob-remote</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -21,8 +21,8 @@
|
||||
|
||||
<logback.version>1.2.9</logback.version>
|
||||
<springboot.version>2.7.4</springboot.version>
|
||||
<powerjob-remote-impl-http.version>4.3.2</powerjob-remote-impl-http.version>
|
||||
<powerjob-remote-impl-akka.version>4.3.2</powerjob-remote-impl-akka.version>
|
||||
<powerjob-remote-impl-http.version>4.3.3</powerjob-remote-impl-http.version>
|
||||
<powerjob-remote-impl-akka.version>4.3.3</powerjob-remote-impl-akka.version>
|
||||
|
||||
<gatling.version>3.9.0</gatling.version>
|
||||
<gatling-maven-plugin.version>4.2.9</gatling-maven-plugin.version>
|
||||
|
@ -5,11 +5,11 @@
|
||||
<parent>
|
||||
<artifactId>powerjob-remote</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<artifactId>powerjob-remote-framework</artifactId>
|
||||
|
||||
<properties>
|
||||
@ -17,7 +17,7 @@
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<powerjob-common.version>4.3.2</powerjob-common.version>
|
||||
<powerjob-common.version>4.3.3</powerjob-common.version>
|
||||
<reflections.version>0.10.2</reflections.version>
|
||||
|
||||
|
||||
|
@ -5,19 +5,19 @@
|
||||
<parent>
|
||||
<artifactId>powerjob-remote</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>powerjob-remote-impl-akka</artifactId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<powerjob-remote-framework.version>4.3.2</powerjob-remote-framework.version>
|
||||
<powerjob-remote-framework.version>4.3.3</powerjob-remote-framework.version>
|
||||
|
||||
<akka.version>2.6.13</akka.version>
|
||||
</properties>
|
||||
|
@ -5,12 +5,12 @@
|
||||
<parent>
|
||||
<artifactId>powerjob-remote</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>powerjob-remote-impl-http</artifactId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
@ -18,7 +18,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<vertx.version>4.3.7</vertx.version>
|
||||
<powerjob-remote-framework.version>4.3.2</powerjob-remote-framework.version>
|
||||
<powerjob-remote-framework.version>4.3.3</powerjob-remote-framework.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -5,12 +5,12 @@
|
||||
<parent>
|
||||
<artifactId>powerjob</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>powerjob-server</artifactId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
@ -49,9 +49,9 @@
|
||||
<groovy.version>3.0.10</groovy.version>
|
||||
<cron-utils.version>9.1.6</cron-utils.version>
|
||||
|
||||
<powerjob-common.version>4.3.2</powerjob-common.version>
|
||||
<powerjob-remote-impl-http.version>4.3.2</powerjob-remote-impl-http.version>
|
||||
<powerjob-remote-impl-akka.version>4.3.2</powerjob-remote-impl-akka.version>
|
||||
<powerjob-common.version>4.3.3</powerjob-common.version>
|
||||
<powerjob-remote-impl-http.version>4.3.3</powerjob-remote-impl-http.version>
|
||||
<powerjob-remote-impl-akka.version>4.3.3</powerjob-remote-impl-akka.version>
|
||||
<springdoc-openapi-ui.version>1.6.14</springdoc-openapi-ui.version>
|
||||
</properties>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>powerjob-server</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>powerjob-server</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -10,6 +10,7 @@ import tech.powerjob.common.enums.TimeExpressionType;
|
||||
import tech.powerjob.common.model.LifeCycle;
|
||||
import tech.powerjob.common.request.ServerStopInstanceReq;
|
||||
import tech.powerjob.common.request.TaskTrackerReportInstanceStatusReq;
|
||||
import tech.powerjob.common.utils.CommonUtils;
|
||||
import tech.powerjob.remote.framework.base.URL;
|
||||
import tech.powerjob.server.common.module.WorkerInfo;
|
||||
import tech.powerjob.server.common.timewheel.holder.HashedWheelTimerHolder;
|
||||
@ -81,6 +82,14 @@ public class InstanceManager implements TransportServiceAware {
|
||||
log.warn("[InstanceManager-{}] can't find InstanceInfo from database", instanceId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 考虑极端情况:Processor 处理耗时小于 server 写 DB 耗时,会导致状态上报时无 taskTracker 地址,此处等待后重新从DB获取数据 GitHub#620
|
||||
if (StringUtils.isEmpty(instanceInfo.getTaskTrackerAddress())) {
|
||||
log.warn("[InstanceManager-{}] TaskTrackerAddress is empty, server will wait then acquire again!", instanceId);
|
||||
CommonUtils.easySleep(277);
|
||||
instanceInfo = instanceInfoRepository.findByInstanceId(instanceId);
|
||||
}
|
||||
|
||||
int originStatus = instanceInfo.getStatus();
|
||||
// 丢弃过期的上报数据
|
||||
if (req.getReportTime() <= instanceInfo.getLastReportTime()) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>powerjob-server</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>powerjob-server</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>powerjob-server</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>powerjob-server</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>powerjob-server</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>powerjob-server</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -58,6 +58,8 @@
|
||||
<version>${springboot.version}</version>
|
||||
<configuration>
|
||||
<mainClass>tech.powerjob.server.PowerJobServerApplication</mainClass>
|
||||
<!-- 支持 server 作为 jar 包被外部系统集成 https://gitee.com/KFCFans/PowerJob/issues/I6H8JF -->
|
||||
<classifier>exec</classifier>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
|
@ -5,24 +5,24 @@
|
||||
<parent>
|
||||
<artifactId>powerjob</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>powerjob-worker-agent</artifactId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
<properties>
|
||||
<powerjob.worker.version>4.3.2</powerjob.worker.version>
|
||||
<powerjob.worker.version>4.3.3</powerjob.worker.version>
|
||||
<logback.version>1.2.9</logback.version>
|
||||
<picocli.version>4.3.2</picocli.version>
|
||||
<spring.version>5.3.23</spring.version>
|
||||
|
||||
<spring.boot.version>2.3.4.RELEASE</spring.boot.version>
|
||||
|
||||
<powerjob.official.processors.version>4.3.2</powerjob.official.processors.version>
|
||||
<powerjob.official.processors.version>4.3.3</powerjob.official.processors.version>
|
||||
|
||||
<!-- dependency for dynamic sql processor -->
|
||||
<mysql.version>8.0.28</mysql.version>
|
||||
|
@ -5,18 +5,18 @@
|
||||
<parent>
|
||||
<artifactId>powerjob</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>powerjob-worker-samples</artifactId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
|
||||
<properties>
|
||||
<springboot.version>2.7.4</springboot.version>
|
||||
<powerjob.worker.starter.version>4.3.2</powerjob.worker.starter.version>
|
||||
<powerjob.worker.starter.version>4.3.3</powerjob.worker.starter.version>
|
||||
<fastjson.version>1.2.83</fastjson.version>
|
||||
<powerjob.official.processors.version>4.3.2</powerjob.official.processors.version>
|
||||
<powerjob.official.processors.version>4.3.3</powerjob.official.processors.version>
|
||||
|
||||
<!-- 部署时跳过该module -->
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
|
@ -0,0 +1,18 @@
|
||||
package tech.powerjob.samples.processors.test;
|
||||
|
||||
import tech.powerjob.worker.core.processor.ProcessResult;
|
||||
import tech.powerjob.worker.core.processor.TaskContext;
|
||||
import tech.powerjob.worker.core.processor.sdk.BasicProcessor;
|
||||
|
||||
/**
|
||||
* ZeroCostTestProcessor
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2023/5/7
|
||||
*/
|
||||
public class ZeroCostTestProcessor implements BasicProcessor {
|
||||
@Override
|
||||
public ProcessResult process(TaskContext context) throws Exception {
|
||||
return new ProcessResult(true, "zero cost");
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package tech.powerjob.samples.tester;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import tech.powerjob.worker.annotation.PowerJobHandler;
|
||||
import tech.powerjob.worker.core.processor.TaskContext;
|
||||
import tech.powerjob.worker.log.OmsLogger;
|
||||
|
||||
@Component(value = "springMethodProcessorService")
|
||||
public class SpringMethodProcessorService {
|
||||
|
||||
/**
|
||||
* 处理器配置方法1: 全限定类名#方法名,比如 tech.powerjob.samples.tester.SpringMethodProcessorService#testEmptyReturn
|
||||
* 处理器配置方法2: SpringBean名称#方法名,比如 springMethodProcessorService#testEmptyReturn
|
||||
* @param context 必须要有入参 TaskContext,返回值可以是 null,也可以是其他任意类型。正常返回代表成功,抛出异常代表执行失败
|
||||
*/
|
||||
@PowerJobHandler(name = "testEmptyReturn")
|
||||
public void testEmptyReturn(TaskContext context) {
|
||||
OmsLogger omsLogger = context.getOmsLogger();
|
||||
omsLogger.warn("测试日志");
|
||||
}
|
||||
|
||||
|
||||
@PowerJobHandler(name = "testNormalReturn")
|
||||
public String testNormalReturn(TaskContext context) {
|
||||
OmsLogger omsLogger = context.getOmsLogger();
|
||||
omsLogger.warn("测试日志");
|
||||
return "testNormalReturn";
|
||||
}
|
||||
|
||||
@PowerJobHandler(name = "testThrowException")
|
||||
public String testThrowException(TaskContext context) {
|
||||
OmsLogger omsLogger = context.getOmsLogger();
|
||||
omsLogger.warn("testThrowException");
|
||||
throw new IllegalArgumentException("test");
|
||||
}
|
||||
}
|
@ -5,16 +5,16 @@
|
||||
<parent>
|
||||
<artifactId>powerjob</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>powerjob-worker-spring-boot-starter</artifactId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<powerjob.worker.version>4.3.2</powerjob.worker.version>
|
||||
<powerjob.worker.version>4.3.3</powerjob.worker.version>
|
||||
<springboot.version>2.7.4</springboot.version>
|
||||
</properties>
|
||||
|
||||
|
@ -5,12 +5,12 @@
|
||||
<parent>
|
||||
<artifactId>powerjob</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>powerjob-worker</artifactId>
|
||||
<version>4.3.2</version>
|
||||
<version>4.3.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
@ -21,10 +21,10 @@
|
||||
|
||||
<logback.version>1.2.9</logback.version>
|
||||
|
||||
<powerjob-common.version>4.3.2</powerjob-common.version>
|
||||
<powerjob-remote-framework.version>4.3.2</powerjob-remote-framework.version>
|
||||
<powerjob-remote-impl-akka.version>4.3.2</powerjob-remote-impl-akka.version>
|
||||
<powerjob-remote-impl-http.version>4.3.2</powerjob-remote-impl-http.version>
|
||||
<powerjob-common.version>4.3.3</powerjob-common.version>
|
||||
<powerjob-remote-framework.version>4.3.3</powerjob-remote-framework.version>
|
||||
<powerjob-remote-impl-akka.version>4.3.3</powerjob-remote-impl-akka.version>
|
||||
<powerjob-remote-impl-http.version>4.3.3</powerjob-remote-impl-http.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -8,6 +8,7 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import tech.powerjob.worker.common.PowerJobWorkerConfig;
|
||||
import tech.powerjob.worker.extension.processor.ProcessorFactory;
|
||||
import tech.powerjob.worker.processor.impl.BuildInSpringMethodProcessorFactory;
|
||||
import tech.powerjob.worker.processor.impl.BuiltInSpringProcessorFactory;
|
||||
|
||||
import java.util.Collections;
|
||||
@ -43,12 +44,14 @@ public class PowerJobSpringWorker implements ApplicationContextAware, Initializi
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
BuiltInSpringProcessorFactory springProcessorFactory = new BuiltInSpringProcessorFactory(applicationContext);
|
||||
|
||||
BuildInSpringMethodProcessorFactory springMethodProcessorFactory = new BuildInSpringMethodProcessorFactory(applicationContext);
|
||||
// append BuiltInSpringProcessorFactory
|
||||
|
||||
List<ProcessorFactory> processorFactories = Lists.newArrayList(
|
||||
Optional.ofNullable(config.getProcessorFactoryList())
|
||||
.orElse(Collections.emptyList()));
|
||||
processorFactories.add(springProcessorFactory);
|
||||
processorFactories.add(springMethodProcessorFactory);
|
||||
config.setProcessorFactoryList(processorFactories);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
package tech.powerjob.worker.annotation;
|
||||
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 方法级别的power-job调度
|
||||
* <a href="https://github.com/PowerJob/PowerJob/pull/610">PR#610</a>
|
||||
*
|
||||
* @author <a href="https://github.com/vannewang">vannewang</a>
|
||||
* @since 2023/4/6
|
||||
*/
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
public @interface PowerJobHandler {
|
||||
|
||||
|
||||
/**
|
||||
* handler name
|
||||
*/
|
||||
String name();
|
||||
|
||||
|
||||
|
||||
}
|
@ -57,7 +57,9 @@ public class ConnectionFactory {
|
||||
// JVM 关闭时删除数据库文件
|
||||
try {
|
||||
FileUtils.forceDeleteOnExit(new File(H2_PATH));
|
||||
}catch (Exception ignore) {
|
||||
log.info("[PowerDatasource] delete worker db file[{}] on JVM exit successfully", H2_PATH);
|
||||
}catch (Throwable t) {
|
||||
log.warn("[PowerDatasource] delete file on JVM exit failed: {}", H2_PATH, t);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,65 @@
|
||||
package tech.powerjob.worker.processor.impl;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import tech.powerjob.common.enums.ProcessorType;
|
||||
import tech.powerjob.worker.extension.processor.ProcessorFactory;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractBuildInSpringProcessorFactory implements ProcessorFactory {
|
||||
|
||||
protected final ApplicationContext applicationContext;
|
||||
|
||||
protected AbstractBuildInSpringProcessorFactory(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> supportTypes() {
|
||||
return Sets.newHashSet(ProcessorType.BUILT_IN.name());
|
||||
}
|
||||
|
||||
protected boolean checkCanLoad() {
|
||||
try {
|
||||
ApplicationContext.class.getClassLoader();
|
||||
return applicationContext != null;
|
||||
} catch (Throwable ignore) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static <T> T getBean(String className, ApplicationContext ctx) throws Exception {
|
||||
|
||||
// 0. 尝试直接用 Bean 名称加载
|
||||
try {
|
||||
final Object bean = ctx.getBean(className);
|
||||
if (bean != null) {
|
||||
return (T) bean;
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
|
||||
// 1. ClassLoader 存在,则直接使用 clz 加载
|
||||
ClassLoader classLoader = ctx.getClassLoader();
|
||||
if (classLoader != null) {
|
||||
return (T) ctx.getBean(classLoader.loadClass(className));
|
||||
}
|
||||
// 2. ClassLoader 不存在(系统类加载器不可见),尝试用类名称小写加载
|
||||
String[] split = className.split("\\.");
|
||||
String beanName = split[split.length - 1];
|
||||
// 小写转大写
|
||||
char[] cs = beanName.toCharArray();
|
||||
cs[0] += 32;
|
||||
String beanName0 = String.valueOf(cs);
|
||||
log.warn("[SpringUtils] can't get ClassLoader from context[{}], try to load by beanName:{}", ctx, beanName0);
|
||||
return (T) ctx.getBean(beanName0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package tech.powerjob.worker.processor.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import tech.powerjob.worker.annotation.PowerJobHandler;
|
||||
import tech.powerjob.worker.extension.processor.ProcessorBean;
|
||||
import tech.powerjob.worker.extension.processor.ProcessorDefinition;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 内建的 SpringBean 处理器工厂,用于加载 Spring 管理Bean下的方法(使用PowerJob注解),非核心依赖
|
||||
*
|
||||
* @author wxp
|
||||
* @since 2023/4/06
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
public class BuildInSpringMethodProcessorFactory extends AbstractBuildInSpringProcessorFactory {
|
||||
|
||||
private static final List<String> jobHandlerRepository = new LinkedList<>();
|
||||
|
||||
private final static String DELIMITER = "#";
|
||||
|
||||
|
||||
public BuildInSpringMethodProcessorFactory(ApplicationContext applicationContext) {
|
||||
super(applicationContext);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ProcessorBean build(ProcessorDefinition processorDefinition) {
|
||||
try {
|
||||
boolean canLoad = checkCanLoad();
|
||||
if (!canLoad) {
|
||||
log.info("[ProcessorFactory] can't find Spring env, this processor can't load by 'BuildInSpringMethodProcessorFactory'");
|
||||
return null;
|
||||
}
|
||||
String processorInfo = processorDefinition.getProcessorInfo();
|
||||
if (!processorInfo.contains(DELIMITER)) {
|
||||
log.info("[ProcessorFactory] can't parse processorDefinition, this processor can't load by 'BuildInSpringMethodProcessorFactory'");
|
||||
return null;
|
||||
}
|
||||
String[] split = processorInfo.split(DELIMITER);
|
||||
String methodName = split[1];
|
||||
String className = split[0];
|
||||
Object bean = getBean(className,applicationContext);
|
||||
Method[] methods = bean.getClass().getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
PowerJobHandler powerJob = method.getAnnotation(PowerJobHandler.class);
|
||||
if (powerJob == null) {
|
||||
continue;
|
||||
}
|
||||
String name = powerJob.name();
|
||||
//匹配到和页面定义相同的methodName
|
||||
if (!name.equals(methodName)) {
|
||||
continue;
|
||||
}
|
||||
if (name.trim().length() == 0) {
|
||||
throw new RuntimeException("method-jobhandler name invalid, for[" + bean.getClass() + "#" + method.getName() + "] .");
|
||||
}
|
||||
if (containsJobHandler(name)) {
|
||||
throw new RuntimeException("jobhandler[" + name + "] naming conflicts.");
|
||||
}
|
||||
method.setAccessible(true);
|
||||
registerJobHandler(methodName);
|
||||
|
||||
MethodBasicProcessor processor = new MethodBasicProcessor(bean, method);
|
||||
return new ProcessorBean()
|
||||
.setProcessor(processor)
|
||||
.setClassLoader(processor.getClass().getClassLoader());
|
||||
}
|
||||
} catch (NoSuchBeanDefinitionException ignore) {
|
||||
log.warn("[ProcessorFactory] can't find the processor in SPRING");
|
||||
} catch (Throwable t) {
|
||||
log.warn("[ProcessorFactory] load by BuiltInSpringProcessorFactory failed. If you are using Spring, make sure this bean was managed by Spring", t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static void registerJobHandler(String name) {
|
||||
jobHandlerRepository.add(name);
|
||||
}
|
||||
|
||||
|
||||
private boolean containsJobHandler(String name) {
|
||||
return jobHandlerRepository.contains(name);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -19,17 +19,11 @@ import java.util.Set;
|
||||
* @since 2023/1/17
|
||||
*/
|
||||
@Slf4j
|
||||
public class BuiltInSpringProcessorFactory implements ProcessorFactory {
|
||||
public class BuiltInSpringProcessorFactory extends AbstractBuildInSpringProcessorFactory {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
public BuiltInSpringProcessorFactory(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> supportTypes() {
|
||||
return Sets.newHashSet(ProcessorType.BUILT_IN.name());
|
||||
super(applicationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,8 +35,12 @@ public class BuiltInSpringProcessorFactory implements ProcessorFactory {
|
||||
log.info("[ProcessorFactory] can't find Spring env, this processor can't load by 'BuiltInSpringProcessorFactory'");
|
||||
return null;
|
||||
}
|
||||
|
||||
BasicProcessor basicProcessor = getBean(processorDefinition.getProcessorInfo(), applicationContext);
|
||||
String processorInfo = processorDefinition.getProcessorInfo();
|
||||
//用于区分方法级别的参数
|
||||
if (processorInfo.contains("#")) {
|
||||
return null;
|
||||
}
|
||||
BasicProcessor basicProcessor = getBean(processorInfo, applicationContext);
|
||||
return new ProcessorBean()
|
||||
.setProcessor(basicProcessor)
|
||||
.setClassLoader(basicProcessor.getClass().getClassLoader());
|
||||
@ -55,42 +53,5 @@ public class BuiltInSpringProcessorFactory implements ProcessorFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean checkCanLoad() {
|
||||
try {
|
||||
ApplicationContext.class.getClassLoader();
|
||||
return applicationContext != null;
|
||||
} catch (Throwable ignore) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T getBean(String className, ApplicationContext ctx) throws Exception {
|
||||
|
||||
// 0. 尝试直接用 Bean 名称加载
|
||||
try {
|
||||
final Object bean = ctx.getBean(className);
|
||||
if (bean != null) {
|
||||
return (T) bean;
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
|
||||
// 1. ClassLoader 存在,则直接使用 clz 加载
|
||||
ClassLoader classLoader = ctx.getClassLoader();
|
||||
if (classLoader != null) {
|
||||
return (T) ctx.getBean(classLoader.loadClass(className));
|
||||
}
|
||||
// 2. ClassLoader 不存在(系统类加载器不可见),尝试用类名称小写加载
|
||||
String[] split = className.split("\\.");
|
||||
String beanName = split[split.length - 1];
|
||||
// 小写转大写
|
||||
char[] cs = beanName.toCharArray();
|
||||
cs[0] += 32;
|
||||
String beanName0 = String.valueOf(cs);
|
||||
log.warn("[SpringUtils] can't get ClassLoader from context[{}], try to load by beanName:{}", ctx, beanName0);
|
||||
return (T) ctx.getBean(beanName0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
package tech.powerjob.worker.processor.impl;
|
||||
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import tech.powerjob.common.serialize.JsonUtils;
|
||||
import tech.powerjob.worker.core.processor.ProcessResult;
|
||||
import tech.powerjob.worker.core.processor.TaskContext;
|
||||
import tech.powerjob.worker.core.processor.sdk.BasicProcessor;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
class MethodBasicProcessor implements BasicProcessor {
|
||||
|
||||
private final Object bean;
|
||||
|
||||
private final Method method;
|
||||
|
||||
public MethodBasicProcessor(Object bean, Method method) {
|
||||
this.bean = bean;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessResult process(TaskContext context) throws Exception {
|
||||
try {
|
||||
Object result = method.invoke(bean, context);
|
||||
return new ProcessResult(true, JsonUtils.toJSONString(result));
|
||||
} catch (InvocationTargetException ite) {
|
||||
ExceptionUtils.rethrow(ite.getTargetException());
|
||||
}
|
||||
|
||||
return new ProcessResult(false, "IMPOSSIBLE");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user