MCPcopy Create free account
hub / github.com/53AI/53AIHub / GetFileProgress

Method GetFileProgress

api/service/progress_storage.go:261–294  ·  view source on GitHub ↗

GetFileProgress 获取文件进度

(batchID, fileID string)

Source from the content-addressed store, hash-verified

259
260// GetFileProgress 获取文件进度
261func (s *ProgressStorage) GetFileProgress(batchID, fileID string) (*FileUpload, error) {
262 key := fmt.Sprintf("file:%s:%s", batchID, fileID)
263
264 // 先查内存缓存
265 if value, ok := s.memoryCache.Load(key); ok {
266 return value.(*FileUpload), nil
267 }
268
269 // 尝试从Redis获取
270 if redisClient := s.ensureRedisConnection(); redisClient != nil {
271 redisKey := fmt.Sprintf("batch_upload:file:%s:%s", batchID, fileID)
272 progressJSON, err := redisClient.Get(context.Background(), redisKey).Result()
273 if err != nil {
274 if err == redis.Nil {
275 return nil, fmt.Errorf("文件进度不存在")
276 }
277 return nil, fmt.Errorf("从Redis获取文件进度失败: %v", err)
278 }
279
280 var fileUpload FileUpload
281 err = json.Unmarshal([]byte(progressJSON), &fileUpload)
282 if err != nil {
283 return nil, fmt.Errorf("反序列化文件进度失败: %v", err)
284 }
285
286 // 回填内存缓存
287 s.memoryCache.Store(key, &fileUpload)
288
289 return &fileUpload, nil
290 }
291
292 // Redis不可用时,只能从内存缓存查找
293 return nil, fmt.Errorf("文件进度不存在")
294}
295
296// GetBatchProgress 获取批次进度
297func (s *ProgressStorage) GetBatchProgress(batchID string, params *ProgressQueryParams) (*BatchProgressResponse, error) {

Callers

nothing calls this directly

Calls 4

ensureRedisConnectionMethod · 0.95
ErrorfMethod · 0.80
LoadMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected