MCPcopy
hub / github.com/kenn-io/msgvault / Execute

Method Execute

internal/deletion/executor.go:218–277  ·  view source on GitHub ↗

Execute performs the deletion for a manifest.

(ctx context.Context, manifestID string, opts *ExecuteOptions)

Source from the content-addressed store, hash-verified

216
217// Execute performs the deletion for a manifest.
218func (e *Executor) Execute(ctx context.Context, manifestID string, opts *ExecuteOptions) error {
219 if opts == nil {
220 opts = DefaultExecuteOptions()
221 }
222
223 manifest, path, err := e.prepareExecution(manifestID, opts.Method)
224 if err != nil {
225 return err
226 }
227
228 // Determine starting point
229 startIndex := 0
230 if opts.Resume && manifest.Execution != nil {
231 startIndex = manifest.Execution.LastProcessedIndex
232 }
233
234 e.logger.Debug("executing deletion",
235 "manifest", manifestID,
236 "total", len(manifest.GmailIDs),
237 "start_index", startIndex,
238 "method", opts.Method,
239 )
240
241 e.progress.OnStart(len(manifest.GmailIDs), startIndex)
242
243 // Execute deletions
244 succeeded := manifest.Execution.Succeeded
245 failed := manifest.Execution.Failed
246 failedIDs := manifest.Execution.FailedIDs
247
248 for i := startIndex; i < len(manifest.GmailIDs); i++ {
249 select {
250 case <-ctx.Done():
251 e.saveCheckpoint(manifest, path, i, succeeded, failed, failedIDs)
252 return ctx.Err()
253 default:
254 }
255
256 result, delErr := e.deleteOne(ctx, manifest.GmailIDs[i], opts.Method)
257 switch result {
258 case resultSuccess:
259 succeeded++
260 case resultFatal:
261 e.saveCheckpoint(manifest, path, i, succeeded, failed, failedIDs)
262 return fmt.Errorf("delete message: %w", delErr)
263 case resultFailed:
264 failed++
265 failedIDs = append(failedIDs, manifest.GmailIDs[i])
266 }
267
268 // Save checkpoint periodically
269 if (i+1)%opts.BatchSize == 0 {
270 e.saveCheckpoint(manifest, path, i+1, succeeded, failed, failedIDs)
271 e.progress.OnProgress(i+1, succeeded, failed)
272 }
273 }
274
275 e.finalizeExecution(manifestID, manifest, path, succeeded, failed, failedIDs, true)

Calls 8

prepareExecutionMethod · 0.95
saveCheckpointMethod · 0.95
deleteOneMethod · 0.95
finalizeExecutionMethod · 0.95
DefaultExecuteOptionsFunction · 0.85
OnStartMethod · 0.65
OnProgressMethod · 0.65
ErrorfMethod · 0.45