-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
340f5c6
commit 500d08c
Showing
11 changed files
with
279 additions
and
71 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/java/com/oneinstep/haidu/config/ParameterResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.oneinstep.haidu.config; | ||
|
||
import com.oneinstep.haidu.context.RequestContext; | ||
|
||
// 支持自定义参数解析器 | ||
public interface ParameterResolver<T> { | ||
T resolve(String value, RequestContext context); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/oneinstep/haidu/config/TaskConfigValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.oneinstep.haidu.config; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class TaskConfigValidator { | ||
|
||
// 验证任务配置的合法性 | ||
public static void validate(TaskConfig config) { | ||
validateArrangeRules(config.getArrangeRule()); | ||
validateTaskDetails(config.getTaskDetailsMap()); | ||
validateParameters(config.getTaskDetailsMap()); | ||
validateCircularDependencies(config); | ||
} | ||
|
||
private static void validateArrangeRules(List<List<String>> arrangeRule) { | ||
} | ||
|
||
private static void validateTaskDetails(Map<String, TaskDetail> taskDetailsMap) { | ||
} | ||
|
||
private static void validateParameters(Map<String, TaskDetail> taskDetailsMap) { | ||
} | ||
|
||
private static void validateCircularDependencies(TaskConfig config) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/oneinstep/haidu/exception/ExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.oneinstep.haidu.exception; | ||
|
||
import com.oneinstep.haidu.context.RequestContext; | ||
|
||
public interface ExceptionHandler { | ||
void handle(String taskId, Throwable e, RequestContext context); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/oneinstep/haidu/exception/RetryStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.oneinstep.haidu.exception; | ||
|
||
// 支持自定义异常重试策略 | ||
public interface RetryStrategy { | ||
boolean shouldRetry(Throwable e, int attempts); | ||
|
||
long getDelayMillis(int attempts); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/oneinstep/haidu/monitor/TaskMonitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.oneinstep.haidu.monitor; | ||
|
||
public interface TaskMonitor { | ||
void onTaskStart(String taskId); | ||
|
||
void onTaskComplete(String taskId, long duration); | ||
|
||
void onTaskError(String taskId, Throwable error); | ||
|
||
void onTaskTimeout(String taskId); | ||
|
||
// 性能指标 | ||
void recordTaskDuration(String taskId, long duration); | ||
|
||
void recordTaskQueueTime(String taskId, long queueTime); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/oneinstep/haidu/scheduler/TaskScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.oneinstep.haidu.scheduler; | ||
|
||
import com.oneinstep.haidu.context.RequestContext; | ||
import com.oneinstep.haidu.core.AbstractTask; | ||
|
||
// 支持自定义任务调度策略 | ||
public interface TaskScheduler { | ||
void schedule(AbstractTask<?> task, RequestContext context); | ||
} |
74 changes: 74 additions & 0 deletions
74
src/test/java/com/oneinstep/haidu/integration/TestTaskTimeout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.oneinstep.haidu.integration; | ||
|
||
import com.oneinstep.haidu.config.JsonTaskDefinitionReader; | ||
import com.oneinstep.haidu.config.TaskConfig; | ||
import com.oneinstep.haidu.config.TaskConfigFactory; | ||
import com.oneinstep.haidu.context.RequestContext; | ||
import com.oneinstep.haidu.core.TaskEngine; | ||
import com.oneinstep.haidu.result.Result; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.StringReader; | ||
import java.util.Map; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
class TestTaskTimeout { | ||
|
||
// 添加更多测试场景 | ||
@Test | ||
void shouldHandleTaskTimeout() throws Exception { | ||
// 准备配置 | ||
String config = """ | ||
{ | ||
"arrangeName": "test-timeout", | ||
"description": "Task timeout test", | ||
"arrangeRule": [ | ||
["timeOutTask"] | ||
], | ||
"taskDetailsMap": { | ||
"timeOutTask": { | ||
"taskId": "timeOutTask", | ||
"fullClassName": "com.oneinstep.haidu.task.TimeOutTask", | ||
"timeout": 1000, | ||
"taskParams": [ | ||
] | ||
} | ||
} | ||
} | ||
"""; | ||
// 创建上下文 | ||
RequestContext context = new RequestContext(); | ||
|
||
// 配置任务 | ||
TaskConfigFactory factory = new TaskConfigFactory(new JsonTaskDefinitionReader()); | ||
TaskConfig taskConfig = factory.createConfig(new StringReader(config)); | ||
context.setTaskConfig(taskConfig); | ||
|
||
// 执行任务 | ||
ExecutorService executorService = Executors.newFixedThreadPool(1); | ||
TaskEngine engine = TaskEngine.getInstance(executorService); | ||
|
||
engine.startEngine(context); | ||
|
||
// 验证结果 | ||
Map<String, Result<?>> results = context.getTaskResultMap(); | ||
Result<?> result = results.get("timeOutTask"); | ||
|
||
// 验证结果 | ||
assertNull(result); | ||
|
||
} | ||
|
||
@Test | ||
void shouldHandleCircularDependencies() { | ||
} | ||
|
||
@Test | ||
void shouldHandleConcurrentTaskExecution() { | ||
} | ||
|
||
} |
Oops, something went wrong.