From 969e23b6800bccce0cf1b55a557e2bb079f4a481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dcaro=20Jerry?= Date: Mon, 7 Jun 2021 20:05:40 -0300 Subject: [PATCH] Update the job failed warning Throw the exception to observers only when the job fails. --- src/Jobs/FeedDocumentJob.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Jobs/FeedDocumentJob.php b/src/Jobs/FeedDocumentJob.php index 235f13c..4f4e469 100644 --- a/src/Jobs/FeedDocumentJob.php +++ b/src/Jobs/FeedDocumentJob.php @@ -6,12 +6,14 @@ use Escavador\Vespa\Common\LogManager; use Escavador\Vespa\Common\Utils; use Escavador\Vespa\Common\VespaExceptionSubject; +use Escavador\Vespa\Enum\LogManagerOptionsEnum; use Escavador\Vespa\Exception\VespaFeedException; use Escavador\Vespa\Models\DocumentDefinition; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; +use Illuminate\Queue\Queue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Redis; @@ -59,7 +61,7 @@ public function handle() try { if (count($documents) == 0) { - $this->logger->log("[$this->model]: No documents to be indexed were returned", "info"); + $this->logger->log("[$this->model]: No documents to be indexed were returned", LogManagerOptionsEnum::INFO); throw new VespaFeedException($this->model, null, "It was not possible to index any document to the Vespa."); } @@ -96,12 +98,22 @@ public function handle() $this->model_class::markAsVespaNotIndexed($chunk); } } - $e = new VespaFeedException($this->model, $ex); - VespaExceptionSubject::notifyObservers($e); - throw $e; + + throw $ex; } $total_duration = Carbon::now()->diffInSeconds($start_time); - $this->logger->log("[$this->model]: Vespa was fed in " . gmdate('H:i:s:m', $total_duration), "info"); - $this->logger->log("[$this->model]: $count_indexed of " . count($documents) . " were indexed in Vespa.", "debug"); + $this->logger->log("[$this->model]: Vespa was fed in " . gmdate('H:i:s:m', $total_duration), LogManagerOptionsEnum::INFO); + $this->logger->log("[$this->model]: $count_indexed of " . count($documents) . " were indexed in Vespa.", LogManagerOptionsEnum::DEBUG); + } + + /** + * The job failed to process. + * + * @param \Exception $exception + * @return void + */ + public function failed(\Exception $exception = null) + { + VespaExceptionSubject::notifyObservers(new VespaFeedException($this->model, $exception)); } }