feat(uploads): an auto-language job is planned without the engines it never runs (#61)
PlanFor(lang) on the Ensemble and a LanguagePlanner the worker prefers: the page lists the other engine (and the fallback if configured), not the base engine, the comparison and the decisions as coming. Found by the PR #62 review. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,13 @@ type Transcriber interface {
|
||||
Transcribe(ctx context.Context, wavPath string) (domain.Transcription, error)
|
||||
}
|
||||
|
||||
// LanguagePlanner is a Planner whose phases depend on the language of the job: a recording
|
||||
// that is not Swedish skips the second engine and the reconcile, and the page should not list
|
||||
// them as coming (tapir#61). The worker prefers it over Planner.
|
||||
type LanguagePlanner interface {
|
||||
PlanFor(lang domain.Language) []progress.Planned
|
||||
}
|
||||
|
||||
// Planner is an optional extra on a Transcriber: it declares its own phases (for
|
||||
// example one per engine) so the page can show them. A Transcriber that does not
|
||||
// implement it gets a single "transcribing" phase from the worker. Whatever a Planner
|
||||
@@ -251,8 +258,14 @@ func (w *Worker) Process(ctx context.Context, job Job) {
|
||||
}
|
||||
|
||||
plan := []progress.Planned{{Key: "received", Label: "Received"}, {Key: "audio", Label: "Preparing the audio"}}
|
||||
lang := job.Language
|
||||
if lang == "" {
|
||||
lang = domain.LangSwedish // queued before the choice existed
|
||||
}
|
||||
planner, planned := w.tr.(Planner)
|
||||
if planned {
|
||||
if lp, ok := w.tr.(LanguagePlanner); ok {
|
||||
plan = append(plan, lp.PlanFor(lang)...)
|
||||
} else if planned {
|
||||
plan = append(plan, planner.Plan()...)
|
||||
} else {
|
||||
plan = append(plan, progress.Planned{Key: "transcribe", Label: "Transcribing"})
|
||||
@@ -313,7 +326,7 @@ func (w *Worker) Process(ctx context.Context, job Job) {
|
||||
if !planned {
|
||||
tr.Begin("transcribe", 0)
|
||||
}
|
||||
t, err := w.tr.Transcribe(domain.WithLanguage(progress.With(jobCtx, tr), job.Language), wav)
|
||||
t, err := w.tr.Transcribe(domain.WithLanguage(progress.With(jobCtx, tr), lang), wav)
|
||||
if err != nil {
|
||||
log.Error("upload: transcribe", "kind", errkind.Of(err), "elapsed", time.Since(start).Round(time.Second))
|
||||
abort(domain.UploadErrTranscriptionFailed)
|
||||
|
||||
Reference in New Issue
Block a user