Fix stuck transcriptions and make transcripts stoppable and searchable.
Raise queue retry_after above the job timeout, recover orphaned runs, allow stop/restart with any engine, and keep finished transcripts searchable in the recordings list.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Recording;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class CancelTranscriptionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Stop an in-progress or queued transcription.
|
||||
*/
|
||||
public function __invoke(Recording $recording): RedirectResponse
|
||||
{
|
||||
if (! $recording->isTranscribing()) {
|
||||
return back()->with('error', 'No transcription is currently running.');
|
||||
}
|
||||
|
||||
$recording->cancelTranscription();
|
||||
|
||||
return back()->with('success', 'Transcription stopped.');
|
||||
}
|
||||
}
|
||||
@@ -17,21 +17,23 @@ class RecordingController extends Controller
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
Recording::query()
|
||||
->whereIn('transcription_status', ['pending', 'processing'])
|
||||
->orderBy('id')
|
||||
->each(fn (Recording $recording) => $recording->recoverOrphanedTranscription());
|
||||
|
||||
$query = Recording::query()->latest();
|
||||
|
||||
if ($search = $request->string('q')->trim()->toString()) {
|
||||
$query->where(function ($builder) use ($search) {
|
||||
$builder->where('title', 'like', "%{$search}%")
|
||||
->orWhere('artist', 'like', "%{$search}%")
|
||||
->orWhere('album', 'like', "%{$search}%")
|
||||
->orWhere('original_filename', 'like', "%{$search}%")
|
||||
->orWhere('transcript', 'like', "%{$search}%");
|
||||
});
|
||||
$query->search($search);
|
||||
}
|
||||
|
||||
$recordings = $query->paginate(20)->withQueryString();
|
||||
|
||||
return view('recordings.index', compact('recordings', 'search'));
|
||||
return view('recordings.index', [
|
||||
'recordings' => $recordings,
|
||||
'search' => $search ?? '',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,6 +79,9 @@ class RecordingController extends Controller
|
||||
*/
|
||||
public function show(Recording $recording): View
|
||||
{
|
||||
$recording->recoverOrphanedTranscription();
|
||||
$recording->refresh();
|
||||
|
||||
return view('recordings.show', compact('recording'));
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,14 @@ class TranscribeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Queue transcription for the recording with the chosen engine.
|
||||
*
|
||||
* Always allowed: stops any current run first, then starts the new engine.
|
||||
*/
|
||||
public function __invoke(TranscribeRecordingRequest $request, Recording $recording): RedirectResponse
|
||||
{
|
||||
if ($recording->transcription_status === 'processing') {
|
||||
return back()->with('error', 'Transcription is already in progress.');
|
||||
if ($recording->isTranscribing() || $recording->hasActiveTranscriptionJob()) {
|
||||
$recording->cancelTranscription(silent: true);
|
||||
$recording->refresh();
|
||||
}
|
||||
|
||||
$driver = $request->validated('driver');
|
||||
@@ -28,8 +31,8 @@ class TranscribeController extends Controller
|
||||
'transcription_percent' => 5,
|
||||
'transcription_started_at' => now(),
|
||||
'transcription_error' => null,
|
||||
'transcript' => null,
|
||||
'transcribed_at' => null,
|
||||
// Keep the previous transcript until a new run succeeds.
|
||||
'transcribed_at' => $recording->transcribed_at,
|
||||
]);
|
||||
|
||||
TranscribeRecording::dispatch($recording->fresh());
|
||||
|
||||
@@ -12,6 +12,12 @@ class TranscriptionStatusController extends Controller
|
||||
*/
|
||||
public function __invoke(Recording $recording): JsonResponse
|
||||
{
|
||||
return response()->json($recording->fresh()->transcriptionStatusPayload());
|
||||
$recording = $recording->fresh();
|
||||
|
||||
if ($recording->recoverOrphanedTranscription()) {
|
||||
$recording->refresh();
|
||||
}
|
||||
|
||||
return response()->json($recording->transcriptionStatusPayload());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user