mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
[fix] fix server always retry failed job's bug
This commit is contained in:
parent
923b3ce0d2
commit
42c3ce3747
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<powerjob.common.version>3.0.0</powerjob.common.version>
|
<powerjob.common.version>3.0.0</powerjob.common.version>
|
||||||
<junit.version>5.6.1</junit.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -25,13 +24,6 @@
|
|||||||
<artifactId>powerjob-common</artifactId>
|
<artifactId>powerjob-common</artifactId>
|
||||||
<version>${powerjob.common.version}</version>
|
<version>${powerjob.common.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Junit 测试 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -20,6 +20,7 @@
|
|||||||
<guava.version>29.0-jre</guava.version>
|
<guava.version>29.0-jre</guava.version>
|
||||||
<okhttp.version>4.4.1</okhttp.version>
|
<okhttp.version>4.4.1</okhttp.version>
|
||||||
<akka.version>2.6.4</akka.version>
|
<akka.version>2.6.4</akka.version>
|
||||||
|
<junit.version>5.6.1</junit.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -68,13 +69,20 @@
|
|||||||
<version>${akka.version}</version>
|
<version>${akka.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- commons-io -->
|
<!-- commons-io -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>${commons.io.version}</version>
|
<version>${commons.io.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Junit 测试 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
61
powerjob-common/src/test/java/SegmentLockTest.java
Normal file
61
powerjob-common/src/test/java/SegmentLockTest.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import com.github.kfcfans.powerjob.common.utils.CommonUtils;
|
||||||
|
import com.github.kfcfans.powerjob.common.utils.SegmentLock;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分段锁测试
|
||||||
|
*
|
||||||
|
* @author tjq
|
||||||
|
* @since 2020/6/15
|
||||||
|
*/
|
||||||
|
public class SegmentLockTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLock() throws Exception {
|
||||||
|
int lockId = 10086;
|
||||||
|
SegmentLock lock = new SegmentLock(4);
|
||||||
|
ExecutorService pool = Executors.newFixedThreadPool(2);
|
||||||
|
pool.execute(() -> {
|
||||||
|
System.out.println("before lock A");
|
||||||
|
lock.lockInterruptibleSafe(lockId);
|
||||||
|
System.out.println("after lock A");
|
||||||
|
});
|
||||||
|
|
||||||
|
pool.execute(() -> {
|
||||||
|
System.out.println("before lock AA");
|
||||||
|
lock.lockInterruptibleSafe(lockId);
|
||||||
|
System.out.println("after lock AA");
|
||||||
|
});
|
||||||
|
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnLock() throws Exception {
|
||||||
|
int lockId = 10086;
|
||||||
|
SegmentLock lock = new SegmentLock(4);
|
||||||
|
ExecutorService pool = Executors.newFixedThreadPool(2);
|
||||||
|
pool.execute(() -> {
|
||||||
|
System.out.println("before lock A");
|
||||||
|
lock.lockInterruptibleSafe(lockId);
|
||||||
|
System.out.println("after lock A");
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
}catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
lock.unlock(lockId);
|
||||||
|
});
|
||||||
|
|
||||||
|
pool.execute(() -> {
|
||||||
|
System.out.println("before lock AA");
|
||||||
|
lock.lockInterruptibleSafe(lockId);
|
||||||
|
System.out.println("after lock AA");
|
||||||
|
});
|
||||||
|
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -139,7 +139,7 @@ public class InstanceStatusCheckService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CRON 和 API一样,失败次数 + 1,根据重试配置进行重试
|
// CRON 和 API一样,失败次数 + 1,根据重试配置进行重试
|
||||||
if (instance.getRunningTimes() > jobInfoDO.getInstanceRetryNum()) {
|
if (instance.getRunningTimes() < jobInfoDO.getInstanceRetryNum()) {
|
||||||
dispatchService.redispatch(jobInfoDO, instance.getInstanceId(), instance.getRunningTimes());
|
dispatchService.redispatch(jobInfoDO, instance.getInstanceId(), instance.getRunningTimes());
|
||||||
}else {
|
}else {
|
||||||
updateFailedInstance(instance);
|
updateFailedInstance(instance);
|
||||||
|
@ -162,6 +162,7 @@ public abstract class TaskTracker {
|
|||||||
|
|
||||||
// 此时本次请求已经有效,先写入最新的时间
|
// 此时本次请求已经有效,先写入最新的时间
|
||||||
taskId2LastReportTime.put(taskId, reportTime);
|
taskId2LastReportTime.put(taskId, reportTime);
|
||||||
|
log.debug("[TaskTracker-{}] task({}) receive new status: {}", instanceId, taskId, newStatus);
|
||||||
|
|
||||||
// 处理失败的情况
|
// 处理失败的情况
|
||||||
int configTaskRetryNum = instanceInfo.getTaskRetryNum();
|
int configTaskRetryNum = instanceInfo.getTaskRetryNum();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user