From b8bc33b8fe5909da7636f606e076f5540a8a423b Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Wed, 28 Jul 2021 07:50:52 +1200 Subject: [PATCH] Better error reporting in queuedjob if indexing fails. --- src/Extensions/AlgoliaObjectExtension.php | 5 ++++- src/Jobs/AlgoliaIndexItemJob.php | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Extensions/AlgoliaObjectExtension.php b/src/Extensions/AlgoliaObjectExtension.php index bee897f..e2189c3 100644 --- a/src/Extensions/AlgoliaObjectExtension.php +++ b/src/Extensions/AlgoliaObjectExtension.php @@ -225,6 +225,8 @@ public function doImmediateIndexInAlgolia() ) ); + $this->owner->AlgoliaError = $e->getMessage(); + return false; } } @@ -246,7 +248,7 @@ public function onAfterUnpublish() */ public function removeFromAlgolia() { - if (!$this->owner->AlgoliaIndexed) { + if (!$this->owner->AlgoliaUUID) { // Not in the index, so skipping return false; } @@ -283,6 +285,7 @@ public function assignAlgoliaUUID($writeImmediately = true) { $uuid = Uuid::uuid4(); $this->owner->AlgoliaUUID = $uuid->toString(); + if ($writeImmediately) { $this->updateAlgoliaFields(['AlgoliaUUID' => "'" . $this->owner->AlgoliaUUID . "'"]); } diff --git a/src/Jobs/AlgoliaIndexItemJob.php b/src/Jobs/AlgoliaIndexItemJob.php index 6577d99..e0919c9 100644 --- a/src/Jobs/AlgoliaIndexItemJob.php +++ b/src/Jobs/AlgoliaIndexItemJob.php @@ -106,9 +106,12 @@ public function process() if (!$obj->AlgoliaUUID) { $obj->assignAlgoliaUUID(); } - $obj->doImmediateIndexInAlgolia(); - $this->addMessage('Record #'. $id .' indexed as objectID '. $obj->AlgoliaUUID); + if ($obj->doImmediateIndexInAlgolia()) { + $this->addMessage('Record #'. $id .' successfully indexed as objectID '. $obj->AlgoliaUUID); + } else { + $this->addMessage('Record #'. $id .' failed to be indexed: '. $obj->AlgoliaError); + } unset($obj); }