Propagate cancellation and preserve resumable state
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user