diff --git a/internal/adapters/store/uploaded_transcripts.go b/internal/adapters/store/uploaded_transcripts.go index 71d289b..a77d160 100644 --- a/internal/adapters/store/uploaded_transcripts.go +++ b/internal/adapters/store/uploaded_transcripts.go @@ -88,12 +88,16 @@ func (s *Store) Heartbeat(ctx context.Context, userID, id string) error { WHERE id = $1 AND user_id = $2`) } -// FailUpload moves an upload to failed with a typed reason. +// FailUpload moves a queued or transcribing upload to failed with a typed reason. A +// finished upload is left as it was: a shutdown can record a job as failed after its +// transcript was already committed (the commit lands, the caller sees a cancelled +// context), and that must not hide the text. Such a call touches no row and returns +// ErrUploadNotFound. func (s *Store) FailUpload(ctx context.Context, userID, id string, kind domain.UploadErrorKind) error { return s.updateUpload(ctx, userID, id, "fail upload", `UPDATE uploaded_transcripts SET status = 'failed', error_kind = $3, finished_at = NOW() - WHERE id = $1 AND user_id = $2`, + WHERE id = $1 AND user_id = $2 AND status IN ('queued', 'transcribing')`, string(kind)) }