Cleanup 清理已完成的任务 清理指定时间之前完成的任务
(before time.Time)
| 232 | // Cleanup 清理已完成的任务 |
| 233 | // 清理指定时间之前完成的任务 |
| 234 | func (e *LongRunningExecutor) Cleanup(before time.Time) int { |
| 235 | var deleted int |
| 236 | |
| 237 | e.tasks.Range(func(key, value any) bool { |
| 238 | status := value.(*TaskStatus) |
| 239 | |
| 240 | // 只清理终态任务 |
| 241 | if status.State.IsTerminal() && status.EndTime != nil { |
| 242 | if status.EndTime.Before(before) { |
| 243 | e.tasks.Delete(key) |
| 244 | e.cancels.Delete(key) |
| 245 | deleted++ |
| 246 | } |
| 247 | } |
| 248 | return true |
| 249 | }) |
| 250 | |
| 251 | return deleted |
| 252 | } |
| 253 | |
| 254 | // UpdateProgress 更新任务进度(供工具内部调用) |
| 255 | func (e *LongRunningExecutor) UpdateProgress(taskID string, progress float64, metadata map[string]any) error { |
no test coverage detected