From b296b4f48b6d38f39fa0b7120960f09761cff6f0 Mon Sep 17 00:00:00 2001 From: Alfred Nutile Date: Thu, 28 Mar 2024 11:58:16 -0400 Subject: [PATCH] try catch on a parse job --- .../Documents/Transformers/PdfTransformer.php | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/app/Domains/Documents/Transformers/PdfTransformer.php b/app/Domains/Documents/Transformers/PdfTransformer.php index a6a71817..5ef0695a 100644 --- a/app/Domains/Documents/Transformers/PdfTransformer.php +++ b/app/Domains/Documents/Transformers/PdfTransformer.php @@ -11,6 +11,7 @@ use App\Models\DocumentChunk; use Illuminate\Bus\Batch; use Illuminate\Support\Facades\Bus; +use Illuminate\Support\Facades\Log; use Smalot\PdfParser\Parser; class PdfTransformer @@ -28,30 +29,34 @@ public function handle(Document $document): Document $pages = $pdf->getPages(); $chunks = []; foreach ($pages as $page_number => $page) { - $page_number = $page_number + 1; - $pageContent = $page->getText(); - $guid = md5($pageContent); - $DocumentChunk = DocumentChunk::updateOrCreate( - [ - 'guid' => $guid, - 'document_id' => $this->document->id, - ], - [ - 'content' => $pageContent, - 'sort_order' => $page_number, - ] - ); - /** - * Soon taggings - * And Summary - */ - $chunks[] = [ - new VectorlizeDataJob($DocumentChunk), - new SummarizeDataJob($DocumentChunk), - //Tagging - ]; + try { + $page_number = $page_number + 1; + $pageContent = $page->getText(); + $guid = md5($pageContent); + $DocumentChunk = DocumentChunk::updateOrCreate( + [ + 'guid' => $guid, + 'document_id' => $this->document->id, + ], + [ + 'content' => $pageContent, + 'sort_order' => $page_number, + ] + ); + /** + * Soon taggings + * And Summary + */ + $chunks[] = [ + new VectorlizeDataJob($DocumentChunk), + new SummarizeDataJob($DocumentChunk), + //Tagging + ]; - CollectionStatusEvent::dispatch($document->collection, CollectionStatusEnum::PROCESSING); + CollectionStatusEvent::dispatch($document->collection, CollectionStatusEnum::PROCESSING); + } catch (\Exception $e) { + Log::error('Error parsing PDF', ['error' => $e->getMessage()]); + } } $batch = Bus::batch($chunks)