(ctx context.Context, args map[string]any)
| 244 | } |
| 245 | |
| 246 | func (t *MockFileUploadTool) StartAsync(ctx context.Context, args map[string]any) (string, error) { |
| 247 | // 使用自定义的执行逻辑 |
| 248 | taskID := "task_" + strconv.FormatInt(time.Now().UnixNano(), 10) |
| 249 | |
| 250 | // 创建任务状态 |
| 251 | status := &tools.TaskStatus{ |
| 252 | TaskID: taskID, |
| 253 | State: tools.TaskStatePending, |
| 254 | Progress: 0.0, |
| 255 | StartTime: time.Now(), |
| 256 | Metadata: make(map[string]any), |
| 257 | } |
| 258 | _ = t.executor.UpdateProgress(taskID, 0.0, nil) |
| 259 | |
| 260 | // 异步执行 |
| 261 | go func() { |
| 262 | fileSize := args["file_size"].(int) |
| 263 | chunkSize := args["chunk_size"].(int) |
| 264 | |
| 265 | chunks := fileSize / chunkSize |
| 266 | for i := range chunks { |
| 267 | select { |
| 268 | case <-ctx.Done(): |
| 269 | return |
| 270 | case <-time.After(100 * time.Millisecond): |
| 271 | progress := float64(i+1) / float64(chunks) |
| 272 | _ = t.executor.UpdateProgress(taskID, progress, map[string]any{ |
| 273 | "uploaded_chunks": i + 1, |
| 274 | "total_chunks": chunks, |
| 275 | }) |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | // 完成 |
| 280 | now := time.Now() |
| 281 | status.State = tools.TaskStateCompleted |
| 282 | status.Progress = 1.0 |
| 283 | status.EndTime = &now |
| 284 | status.Result = map[string]any{ |
| 285 | "uploaded_bytes": fileSize, |
| 286 | "chunks": chunks, |
| 287 | } |
| 288 | }() |
| 289 | |
| 290 | return taskID, nil |
| 291 | } |
| 292 | |
| 293 | func (t *MockFileUploadTool) Execute(ctx context.Context, args map[string]any) (any, error) { |
| 294 | // 简化的同步执行 |
no test coverage detected