document = $document; $this->tries = config('documents.conversion.retry_times', 3); $this->timeout = config('documents.conversion.timeout', 300); $this->backoff = config('documents.conversion.retry_delay', 60); } public function handle(DocumentConversionService $conversionService): void { try { Log::info('开始转换文档', [ 'document_id' => $this->document->id, 'document_title' => $this->document->title, 'file_name' => $this->document->file_name, 'attempt' => $this->attempts(), ]); $result = $conversionService->convertToMarkdown($this->document); $markdownPath = $conversionService->saveMarkdownToFile( $this->document, $result['markdown'] ); $conversionService->updateDocumentMarkdown($this->document, $markdownPath); Log::info('文档转换成功', [ 'document_id' => $this->document->id, 'document_title' => $this->document->title, 'markdown_path' => $markdownPath, ]); } catch (\Exception $e) { Log::error('文档转换失败', [ 'document_id' => $this->document->id, 'document_title' => $this->document->title, 'file_name' => $this->document->file_name, 'attempt' => $this->attempts(), 'error' => $e->getMessage(), ]); if ($this->attempts() >= $this->tries) { $conversionService->handleConversionFailure($this->document, $e); } throw $e; } } public function failed(\Throwable $exception): void { Log::error('文档转换任务最终失败', [ 'document_id' => $this->document->id, 'document_title' => $this->document->title, 'file_name' => $this->document->file_name, 'error' => $exception->getMessage(), ]); $conversionService = app(DocumentConversionService::class); $conversionService->handleConversionFailure( $this->document, $exception instanceof \Exception ? $exception : new \Exception($exception->getMessage()) ); } }