Skip to content

Commit 6af64dc

Browse files
Merge pull request #34 from daniellienert/feature/failure-trehsold-for-switching-index
FEATURE: Introduce threshold for failed jobs for index switching
2 parents d6e179d + ddaeea7 commit 6af64dc

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

Classes/UpdateAliasJob.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ class UpdateAliasJob implements JobInterface
3838
*/
3939
protected $indexPostfix;
4040

41+
/**
42+
* @Flow\InjectConfiguration(path="acceptedFailedJobs")
43+
* @var int
44+
*/
45+
protected $acceptedFailedJobs = -1;
46+
4147
/**
4248
* @param string $indexPostfix
4349
*/
@@ -48,9 +54,6 @@ public function __construct($indexPostfix)
4854
}
4955

5056
/**
51-
* Execute the job
52-
* A job should finish itself after successful execution using the queue methods.
53-
*
5457
* @param QueueInterface $queue
5558
* @param Message $message The original message
5659
* @return boolean TRUE if the job was executed successfully and the message should be finished
@@ -60,9 +63,13 @@ public function __construct($indexPostfix)
6063
*/
6164
public function execute(QueueInterface $queue, Message $message): bool
6265
{
63-
$this->nodeIndexer->setIndexNamePostfix($this->indexPostfix);
64-
$this->nodeIndexer->updateIndexAlias();
65-
$this->log(sprintf('action=indexing step=index-switched alias=%s', $this->indexPostfix), LOG_NOTICE);
66+
if ($this->shouldIndexBeSwitched($queue)) {
67+
$this->nodeIndexer->setIndexNamePostfix($this->indexPostfix);
68+
$this->nodeIndexer->updateIndexAlias();
69+
$this->log(sprintf('action=indexing step=index-switched alias=%s message="Index was switched successfully"', $this->indexPostfix), LOG_NOTICE);
70+
} else {
71+
$this->log(sprintf('action=indexing step=index-switched alias=%s message="Index was not switched due to %s failed batches in the current queue"', $this->indexPostfix, $queue->countFailed()), LOG_ERR);
72+
}
6673

6774
return true;
6875
}
@@ -86,4 +93,21 @@ public function getLabel(): string
8693
{
8794
return sprintf('ElasticSearch Indexing Job (%s)', $this->getIdentifier());
8895
}
96+
97+
/**
98+
* @param QueueInterface $queue
99+
* @return bool
100+
*/
101+
protected function shouldIndexBeSwitched(QueueInterface $queue): bool
102+
{
103+
if ($this->acceptedFailedJobs === -1) {
104+
return true;
105+
}
106+
107+
if ($queue->countFailed() <= $this->acceptedFailedJobs) {
108+
return true;
109+
}
110+
111+
return false;
112+
}
89113
}

Configuration/Settings.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Flowpack:
44
enableLiveAsyncIndexing: true
55
# Change size of single batch jobs via this setting
66
batchSize: 500
7+
8+
# Number of failed jobs accepted to switch the alias to the new index
9+
# -1 means, accept any number of failures
10+
acceptedFailedJobs: 0
11+
712
JobQueue:
813
Common:
914
presets:

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ You can use this CLI command to process indexing job:
8080

8181
# Supervisord configuration
8282

83-
You can use tools like ```supervisord``` to manage long runing process. Bellow you can
84-
found a basic configuration:
83+
You can use tools like ```supervisord``` to manage long running processes. Bellow you can find a basic configuration:
8584

8685
[supervisord]
8786

0 commit comments

Comments
 (0)