Files
AndyTranscribe/app/Jobs/TranscribeRecording.php
T

61 lines
1.4 KiB
PHP

<?php
namespace App\Jobs;
use App\Models\Recording;
use App\Services\TranscriptionService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Log;
use Throwable;
class TranscribeRecording implements ShouldQueue
{
use Queueable;
/**
* The number of seconds the job can run before timing out.
*/
public int $timeout = 600;
/**
* Create a new job instance.
*/
public function __construct(public Recording $recording)
{
//
}
/**
* Execute the job.
*/
public function handle(TranscriptionService $transcription): void
{
$this->recording->update([
'transcription_status' => 'processing',
]);
try {
$text = $transcription->transcribe($this->recording);
$this->recording->update([
'transcript' => $text,
'transcription_status' => 'done',
'transcribed_at' => now(),
]);
} catch (Throwable $e) {
Log::error('Transcription failed', [
'recording_id' => $this->recording->id,
'driver' => $this->recording->transcription_driver,
'message' => $e->getMessage(),
]);
$this->recording->update([
'transcription_status' => 'failed',
]);
throw $e;
}
}
}