Skip to content

Commit

Permalink
Better error reporting in queuedjob if indexing fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Jul 27, 2021
1 parent a3dcbed commit b8bc33b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Extensions/AlgoliaObjectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ public function doImmediateIndexInAlgolia()
)
);

$this->owner->AlgoliaError = $e->getMessage();

return false;
}
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 . "'"]);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Jobs/AlgoliaIndexItemJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b8bc33b

Please sign in to comment.