Skip to content

Commit f168c9d

Browse files
authored
allow indexing errors to be ignored (#9)
1 parent 723523e commit f168c9d

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/Index/AbstractIndex.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,9 @@ final public function indexingLock(): Lock
174174
{
175175
return Cache::lock(__CLASS__.$this->getName());
176176
}
177+
178+
public function ingoreIndexingErrors(): bool
179+
{
180+
return false;
181+
}
177182
}

src/Index/IndexInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,12 @@ public function getModelInstance(Document $document): Model;
145145
public function getDocumentInstance(Model|ElasticsearchableInterface $model): ?Document;
146146

147147
public function indexingLock(): Lock;
148+
149+
/**
150+
* Should errors during indexing be ignored?
151+
* Recommendation: set getBatchSize() to 1 if this is enabled.
152+
*
153+
* @return bool
154+
*/
155+
public function ingoreIndexingErrors(): bool;
148156
}

src/Jobs/PopulateBatchIndex.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Illuminate\Queue\SerializesModels;
1414
use Limenet\LaravelElasticaBridge\Index\IndexInterface;
1515
use Limenet\LaravelElasticaBridge\Model\ElasticsearchableInterface;
16+
use Throwable;
1617

1718
class PopulateBatchIndex implements ShouldQueue
1819
{
@@ -53,6 +54,12 @@ public function handle(): void
5354
return;
5455
}
5556

56-
$this->index->addDocuments($esDocuments);
57+
try {
58+
$this->index->addDocuments($esDocuments);
59+
} catch (Throwable $th) {
60+
if (! $this->indexConfig->ingoreIndexingErrors()) {
61+
throw $th;
62+
}
63+
}
5764
}
5865
}

0 commit comments

Comments
 (0)