Commit 7d856c7e authored by Emiliano Balbuena's avatar Emiliano Balbuena

(fix): Bad CQL; (chore): Style and logging

1 merge request!250(feat): Retry queue for ElasticSearch
Pipeline #69287863 passed with stages
in 6 minutes and 52 seconds
......@@ -50,19 +50,18 @@ class DispatchIndexDelegate
public function index($entity)
{
try {
$success = (bool) $this->searchIndex->index($entity);
$indexed = (bool) $this->searchIndex->index($entity);
} catch (Exception $e) {
error_log("[DispatchIndexDelegate] {$e}");
$success = false;
$indexed = false;
}
$urn = (string) (new Urn($entity->guid));
if ($success) {
if ($indexed) {
$retryQueueEntry = new RetryQueueEntry();
$retryQueueEntry
->setEntityUrn($urn)
->setLastRetry(time());
->setEntityUrn($urn);
$this->retryQueueRepository->delete($retryQueueEntry);
} else {
......@@ -73,15 +72,19 @@ class DispatchIndexDelegate
->setLastRetry(time())
->setRetries($retries);
$this->retryQueueRepository->add($retryQueueEntry);
$retrySaved = $this->retryQueueRepository->add($retryQueueEntry);
if (!$retrySaved) {
error_log("[DispatchIndexDelegate] Critical: Cannot save retry to queue table: {$urn}");
} elseif ($retries < 5) {
error_log("[DispatchIndexDelegate] Warn: Re-queue: {$urn}");
if ($retries < 5) {
$this->eventsDispatcher->trigger('search:index', 'all', [
'entity' => $entity
]);
}
}
return $success;
return $indexed;
}
}
......@@ -116,14 +116,14 @@ class Repository
public function add(RetryQueueEntry $retryQueueEntry)
{
if (!$retryQueueEntry->getEntityUrn()) {
throw new \Exception('Missing URN');
throw new Exception('Missing URN');
}
$cql = "INSERT INTO search_dispatcher_queue (entity_urn, last_retry, retries) VALUES (?, ?, ?,)";
$cql = "INSERT INTO search_dispatcher_queue (entity_urn, last_retry, retries) VALUES (?, ?, ?)";
$values = [
(string) $retryQueueEntry->getEntityUrn(),
new Timestamp($retryQueueEntry->getLastRetry()),
(int) $retryQueueEntry->getRetries(),
new Timestamp($retryQueueEntry->getLastRetry()),
(int) $retryQueueEntry->getRetries(),
];
$prepared = new Custom();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment