feat(api): 支持取消本地排队任务
This commit is contained in:
@@ -256,6 +256,38 @@ WHERE id = $1::uuid`,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Store) CancelQueuedTask(ctx context.Context, taskID string, message string) (GatewayTask, bool, error) {
|
||||
message = strings.TrimSpace(message)
|
||||
if message == "" {
|
||||
message = "任务已取消"
|
||||
}
|
||||
tag, err := s.pool.Exec(ctx, `
|
||||
UPDATE gateway_tasks
|
||||
SET status = 'cancelled',
|
||||
error = NULLIF($2::text, ''),
|
||||
error_code = 'task_cancelled',
|
||||
error_message = NULLIF($2::text, ''),
|
||||
locked_by = NULL,
|
||||
locked_at = NULL,
|
||||
heartbeat_at = NULL,
|
||||
finished_at = now(),
|
||||
updated_at = now()
|
||||
WHERE id = $1::uuid
|
||||
AND status = 'queued'
|
||||
AND COALESCE(remote_task_id, '') = ''`, taskID, message)
|
||||
if err != nil {
|
||||
return GatewayTask{}, false, err
|
||||
}
|
||||
if tag.RowsAffected() == 0 {
|
||||
return GatewayTask{}, false, nil
|
||||
}
|
||||
task, err := s.GetTask(ctx, taskID)
|
||||
if err != nil {
|
||||
return GatewayTask{}, true, err
|
||||
}
|
||||
return task, true, nil
|
||||
}
|
||||
|
||||
func (s *Store) ListRecoverableAsyncTasks(ctx context.Context, limit int) ([]AsyncTaskQueueItem, error) {
|
||||
if limit <= 0 {
|
||||
limit = 500
|
||||
|
||||
Reference in New Issue
Block a user