Propagate cancellation and preserve resumable state

This commit is contained in:
2026-11-20 05:53:49 +00:00
parent a6c6f1e4ab
commit c7a5ff316d
21 changed files with 356 additions and 27 deletions

View File

@@ -3,6 +3,7 @@ package stage
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
@@ -86,6 +87,9 @@ func (transcribeStage) Run(ctx context.Context, env *Env, m *manifest.Manifest)
group, groupCtx := errgroup.WithContext(ctx)
group.SetLimit(concurrency)
for _, job := range jobs {
if groupCtx.Err() != nil {
break
}
job := job
group.Go(func() error {
if err := groupCtx.Err(); err != nil {
@@ -116,13 +120,10 @@ func (transcribeStage) Run(ctx context.Context, env *Env, m *manifest.Manifest)
return nil
})
}
groupErr := group.Wait()
if err := state.checkpointFailure(); err != nil {
return nil, err
}
groupErr := errors.Join(group.Wait(), state.checkpointFailure())
completedCount := state.completedCount()
if err := ctx.Err(); err != nil {
return nil, fmt.Errorf("transcribe: canceled after completing %d of %d audio jobs: %w", completedCount, len(jobs), err)
return nil, errors.Join(fmt.Errorf("transcribe: canceled after completing %d of %d audio jobs: %w", completedCount, len(jobs), err), groupErr)
}
if groupErr != nil {
return nil, groupErr