feat: implement V2 alert center and scoped alert governance

This commit is contained in:
Yvan
2026-11-05 20:08:29 +08:00
parent f8e26c5baf
commit 999c9a6315
57 changed files with 2711 additions and 216 deletions
+7 -1
View File
@@ -217,7 +217,13 @@ func (e *TaskExecutor) runMethod(ctx context.Context, task *taskbiz.TimedTask) e
}
for attempt := 0; attempt <= options.MaxRetryTimes; attempt++ {
err = e.runMethodAttempt(ctx, task, method, options.Timeout)
if err == nil || ctx.Err() != nil || errors.Is(err, context.Canceled) || e.methodOrphaned(task.ID) {
if ctxErr := ctx.Err(); ctxErr != nil {
if errors.Is(ctxErr, context.DeadlineExceeded) {
return errTaskTimeout
}
return ctxErr
}
if err == nil || errors.Is(err, context.Canceled) || e.methodOrphaned(task.ID) {
return err
}
if attempt < options.MaxRetryTimes {
+13
View File
@@ -95,6 +95,19 @@ func TestRunMethodCancellationStopsRetryDelay(t *testing.T) {
}
}
func TestRunMethodCancellationWinsConcurrentAttemptFailure(t *testing.T) {
for i := 0; i < 32; i++ {
ctx, cancel := context.WithCancel(context.Background())
registry := platformtask.NewRegistry()
registry.Register(platformtask.Method{Name: "cancel-at-return", Run: func(context.Context, json.RawMessage) error { cancel(); return errors.New("temporary") }})
err := (&TaskExecutor{methods: registry}).runMethod(ctx, &taskbiz.TimedTask{MethodName: "cancel-at-return", Params: []byte(`{"_execution":{"maxRetryTimes":3,"retryIntervalSeconds":60}}`)})
cancel()
if !errors.Is(err, context.Canceled) {
t.Fatalf("并发取消被执行错误覆盖: %v", err)
}
}
}
func TestRunMethodUsesParentContext(t *testing.T) {
const methodName = "worker-test-parent-context"
started := make(chan struct{})