mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-09 00:56:37 +08:00
fix(task): fix manual retry button visibility and validation
- Only show the manual retry button for failed tasks (status === "failed") on the frontend. - Remove the maximum retry limit validation for manual retries in the task executor. - Remove obsolete test cases verifying maximum retry limit for manual retries.
This commit is contained in:
@@ -379,7 +379,7 @@ export function TaskExecutionsManager() {
|
|||||||
{detailLoading ? <Spinner className="size-4" /> : <RefreshCw className="size-4" />}
|
{detailLoading ? <Spinner className="size-4" /> : <RefreshCw className="size-4" />}
|
||||||
刷新详情
|
刷新详情
|
||||||
</Button>
|
</Button>
|
||||||
{selectedExecution && selectedExecution.status !== "pending" && selectedExecution.status !== "running" && selectedExecution.retryable && selectedExecution.retry_count < selectedExecution.max_retry && (
|
{selectedExecution && selectedExecution.status === "failed" && selectedExecution.retryable && (
|
||||||
<Button onClick={handleRetryExecution} disabled={retrying}>
|
<Button onClick={handleRetryExecution} disabled={retrying}>
|
||||||
{retrying ? <Spinner className="size-4" /> : <RotateCcw className="size-4" />}
|
{retrying ? <Spinner className="size-4" /> : <RotateCcw className="size-4" />}
|
||||||
重试任务
|
重试任务
|
||||||
|
|||||||
@@ -491,32 +491,3 @@ func TestRetryTask(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusBadRequest, w.Code)
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRetryTaskMaxRetryExceeded(t *testing.T) {
|
|
||||||
cleanup := setupTaskTestEnvironment(t)
|
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
adminUser := &model.User{ID: 1001, Username: "admin", IsAdmin: true}
|
|
||||||
router := setupTestRouter(adminUser)
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
execution := &model.TaskExecution{
|
|
||||||
TaskID: "retry_max_api_001",
|
|
||||||
TaskType: "system:cleanup",
|
|
||||||
TaskName: "系统垃圾清理",
|
|
||||||
Status: model.TaskExecutionStatusFailed,
|
|
||||||
Retryable: true,
|
|
||||||
MaxRetry: 1,
|
|
||||||
RetryCount: 1,
|
|
||||||
TriggeredBy: "retry",
|
|
||||||
}
|
|
||||||
err := model.CreateTaskExecution(ctx, execution)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
url := fmt.Sprintf("/api/v1/admin/tasks/executions/%d/retry", execution.ID)
|
|
||||||
req, _ := http.NewRequest("POST", url, nil)
|
|
||||||
w := httptest.NewRecorder()
|
|
||||||
router.ServeHTTP(w, req)
|
|
||||||
|
|
||||||
assert.Equal(t, http.StatusBadRequest, w.Code)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -163,10 +163,6 @@ func RetryTask(ctx context.Context, id uint64) (string, error) {
|
|||||||
return "", errors.New(errTaskNotRetryable)
|
return "", errors.New(errTaskNotRetryable)
|
||||||
}
|
}
|
||||||
|
|
||||||
if execution.RetryCount >= execution.MaxRetry {
|
|
||||||
return "", fmt.Errorf(errTaskMaxRetryExceeded, execution.MaxRetry)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 生成新的 TaskID
|
// 生成新的 TaskID
|
||||||
newTaskID := generateRetryTaskID(execution.TaskID, execution.RetryCount+1)
|
newTaskID := generateRetryTaskID(execution.TaskID, execution.RetryCount+1)
|
||||||
|
|
||||||
|
|||||||
@@ -339,29 +339,6 @@ func TestRetryTaskNotRetryable(t *testing.T) {
|
|||||||
assert.Contains(t, err.Error(), "不支持重试")
|
assert.Contains(t, err.Error(), "不支持重试")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRetryTaskMaxRetryExceeded(t *testing.T) {
|
|
||||||
cleanup := setupTest(t)
|
|
||||||
defer cleanup()
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
execution := &model.TaskExecution{
|
|
||||||
TaskID: "retry_max_001",
|
|
||||||
TaskType: testTaskType,
|
|
||||||
TaskName: "测试任务",
|
|
||||||
Status: model.TaskExecutionStatusFailed,
|
|
||||||
Retryable: true,
|
|
||||||
MaxRetry: 2,
|
|
||||||
RetryCount: 2,
|
|
||||||
TriggeredBy: "retry",
|
|
||||||
}
|
|
||||||
err := model.CreateTaskExecution(ctx, execution)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
_, err = RetryTask(ctx, execution.ID)
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "已达到最大重试次数")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRetryTaskNonExistent(t *testing.T) {
|
func TestRetryTaskNonExistent(t *testing.T) {
|
||||||
cleanup := setupTest(t)
|
cleanup := setupTest(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|||||||
Reference in New Issue
Block a user