Skip to content

Commit 06b5b49

Browse files
committed
[TASK] Add UpdateAliasJob to switch the new index after processing all jobs
1 parent 60f3afd commit 06b5b49

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

Classes/Flowpack/ElasticSearch/ContentRepositoryQueueIndexer/Command/NodeIndexQueueCommandController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
88
use Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\Domain\Repository\NodeDataRepository;
99
use Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\IndexingJob;
10+
use Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\UpdateAliasJob;
1011
use TYPO3\Flow\Annotations as Flow;
1112
use TYPO3\Flow\Cli\CommandController;
1213
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Mapping\NodeTypeMappingBuilder;
@@ -81,6 +82,11 @@ public function buildCommand($workspace = NULL) {
8182
} else {
8283
$this->indexWorkspace($workspace, $indexPostfix);
8384
}
85+
$updateAliasJob = new UpdateAliasJob($indexPostfix);
86+
$this->jobManager->queue('Flowpack.ElasticSearch.ContentRepositoryQueueIndexer', $updateAliasJob);
87+
88+
$this->outputLine();
89+
$this->outputLine('Indexing jobs created with success ...');
8490
}
8591

8692
/**
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
namespace Flowpack\ElasticSearch\ContentRepositoryQueueIndexer;
3+
4+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer;
5+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface;
6+
use TYPO3\Flow\Annotations as Flow;
7+
use TYPO3\Flow\Utility\Algorithms;
8+
use TYPO3\Jobqueue\Common\Job\JobInterface;
9+
use TYPO3\Jobqueue\Common\Queue\Message;
10+
use TYPO3\Jobqueue\Common\Queue\QueueInterface;
11+
use TYPO3\TYPO3CR\Domain\Factory\NodeFactory;
12+
use TYPO3\TYPO3CR\Domain\Model\NodeData;
13+
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
14+
use TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository;
15+
use TYPO3\TYPO3CR\Domain\Service\ContextFactory;
16+
17+
/**
18+
* ElasticSearch Indexing Job Interface
19+
*/
20+
class UpdateAliasJob implements JobInterface {
21+
22+
/**
23+
* @var NodeIndexer
24+
* @Flow\Inject
25+
*/
26+
protected $nodeIndexer;
27+
28+
/**
29+
* @var LoggerInterface
30+
* @Flow\Inject
31+
*/
32+
protected $logger;
33+
34+
/**
35+
* @var string
36+
*/
37+
protected $identifier;
38+
39+
/**
40+
* @var string
41+
*/
42+
protected $indexPostfix;
43+
44+
/**
45+
* @param string $indexPostfix
46+
* @param string $workspaceName
47+
* @param array $nodes
48+
*/
49+
public function __construct($indexPostfix) {
50+
$this->identifier = Algorithms::generateRandomString(24);
51+
$this->indexPostfix = $indexPostfix;
52+
}
53+
54+
/**
55+
* Execute the job
56+
* A job should finish itself after successful execution using the queue methods.
57+
*
58+
* @param QueueInterface $queue
59+
* @param Message $message The original message
60+
* @return boolean TRUE if the job was executed successfully and the message should be finished
61+
*/
62+
public function execute(QueueInterface $queue, Message $message) {
63+
$this->nodeIndexer->setIndexNamePostfix($this->indexPostfix);
64+
$this->nodeIndexer->updateIndexAlias();
65+
$this->logger->log(sprintf('Update Index Alias (%s)', $this->indexPostfix), LOG_NOTICE);
66+
67+
return TRUE;
68+
}
69+
70+
/**
71+
* Get an optional identifier for the job
72+
*
73+
* @return string A job identifier
74+
*/
75+
public function getIdentifier() {
76+
return $this->identifier;
77+
}
78+
79+
/**
80+
* Get a readable label for the job
81+
*
82+
* @return string A label for the job
83+
*/
84+
public function getLabel() {
85+
return sprintf('ElasticSearch Indexing Job (%s)', $this->getIdentifier());
86+
}
87+
88+
}

0 commit comments

Comments
 (0)