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

Method SaveBatch

api/service/progress_storage.go:168–192  ·  view source on GitHub ↗

SaveBatch 保存批次信息

(batch *BatchUpload)

Source from the content-addressed store, hash-verified

166
167// SaveBatch 保存批次信息
168func (s *ProgressStorage) SaveBatch(batch *BatchUpload) error {
169 // 保存到内存缓存
170 s.memoryCache.Store(fmt.Sprintf("batch:%s", batch.ID), batch)
171
172 // 尝试保存到Redis
173 if redisClient := s.ensureRedisConnection(); redisClient != nil {
174 batchJSON, err := json.Marshal(batch)
175 if err != nil {
176 return fmt.Errorf("序列化批次信息失败: %v", err)
177 }
178
179 key := fmt.Sprintf("batch_upload:batch:%s", batch.ID)
180 err = redisClient.Set(context.Background(), key, batchJSON, s.batchTimeout).Err()
181 if err != nil {
182 // Redis错误不应该阻止操作,只记录警告
183 fmt.Printf("警告: 保存批次到Redis失败: %v\n", err)
184 }
185
186 // 更新最后更新时间
187 lastUpdateKey := fmt.Sprintf("batch_upload:last_update:%s", batch.ID)
188 redisClient.Set(context.Background(), lastUpdateKey, time.Now().UnixMilli(), s.batchTimeout)
189 }
190
191 return nil
192}
193
194// LoadBatch 加载批次信息
195func (s *ProgressStorage) LoadBatch(batchID string) (*BatchUpload, error) {

Callers 5

CreateBatchMethod · 0.80
updateBatchStatusMethod · 0.80
CancelBatchMethod · 0.80
CompleteBatchMethod · 0.80
CleanupFailedBatchMethod · 0.80

Calls 5

ensureRedisConnectionMethod · 0.95
ErrorfMethod · 0.80
ErrMethod · 0.80
SetMethod · 0.80
PrintfMethod · 0.80

Tested by

no test coverage detected