UpdateFileProgress 更新文件进度
(batchID, fileID string, fileUpload *FileUpload)
| 237 | |
| 238 | // UpdateFileProgress 更新文件进度 |
| 239 | func (s *ProgressStorage) UpdateFileProgress(batchID, fileID string, fileUpload *FileUpload) error { |
| 240 | // 更新内存缓存 |
| 241 | key := fmt.Sprintf("file:%s:%s", batchID, fileID) |
| 242 | s.memoryCache.Store(key, fileUpload) |
| 243 | |
| 244 | // 尝试异步更新Redis |
| 245 | if redisClient := s.ensureRedisConnection(); redisClient != nil { |
| 246 | go func() { |
| 247 | progressJSON, _ := json.Marshal(fileUpload) |
| 248 | redisKey := fmt.Sprintf("batch_upload:file:%s:%s", batchID, fileID) |
| 249 | redisClient.Set(context.Background(), redisKey, progressJSON, s.cacheTimeout) |
| 250 | |
| 251 | // 更新批次最后更新时间 |
| 252 | lastUpdateKey := fmt.Sprintf("batch_upload:last_update:%s", batchID) |
| 253 | redisClient.Set(context.Background(), lastUpdateKey, time.Now().UnixMilli(), s.batchTimeout) |
| 254 | }() |
| 255 | } |
| 256 | |
| 257 | return nil |
| 258 | } |
| 259 | |
| 260 | // GetFileProgress 获取文件进度 |
| 261 | func (s *ProgressStorage) GetFileProgress(batchID, fileID string) (*FileUpload, error) { |
no test coverage detected