MCPcopy Create free account
hub / github.com/astercloud/aster / cleanupExample

Function cleanupExample

examples/long-running-tools/main.go:169–191  ·  view source on GitHub ↗

cleanupExample 任务清理示例

(ctx context.Context)

Source from the content-addressed store, hash-verified

167
168// cleanupExample 任务清理示例
169func cleanupExample(ctx context.Context) {
170 executor := tools.NewLongRunningExecutor()
171 tool := NewMockDataProcessingTool(executor)
172
173 // 创建一些任务
174 for range 3 {
175 taskID, _ := tool.StartAsync(ctx, map[string]any{
176 "data_size": 100,
177 "delay_ms": 100,
178 })
179 _, _ = tools.WaitForCompletion(executor, taskID, 50*time.Millisecond, 2*time.Second)
180 }
181
182 fmt.Println("✅ Created 3 completed tasks")
183
184 // 清理 1 秒前的任务
185 deleted := executor.Cleanup(time.Now().Add(-1 * time.Second))
186 fmt.Printf("✅ Cleaned up %d old tasks\n", deleted)
187
188 // 验证
189 remaining := executor.ListTasks(nil)
190 fmt.Printf("✅ Remaining tasks: %d\n", len(remaining))
191}
192
193// ============================================================
194// 模拟工具实现

Callers 1

mainFunction · 0.85

Calls 8

CleanupMethod · 0.95
ListTasksMethod · 0.95
NewLongRunningExecutorFunction · 0.92
WaitForCompletionFunction · 0.92
PrintfMethod · 0.80
StartAsyncMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected