Skip to content

Commit 092cda5

Browse files
committed
TASK: Check if the index queue is empty before building and improve CLI output
1 parent 6ee665a commit 092cda5

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class NodeIndexQueueCommandController extends CommandController
2828
const QUEUE_NAME = 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer';
2929

3030
/**
31-
* @Flow\Inject
3231
* @var JobManager
32+
* @Flow\Inject
3333
*/
3434
protected $jobManager;
3535

@@ -46,26 +46,26 @@ class NodeIndexQueueCommandController extends CommandController
4646
protected $persistenceManager;
4747

4848
/**
49-
* @Flow\Inject
5049
* @var NodeTypeMappingBuilder
50+
* @Flow\Inject
5151
*/
5252
protected $nodeTypeMappingBuilder;
5353

5454
/**
55-
* @Flow\Inject
5655
* @var NodeDataRepository
56+
* @Flow\Inject
5757
*/
5858
protected $nodeDataRepository;
5959

6060
/**
61-
* @Flow\Inject
6261
* @var WorkspaceRepository
62+
* @Flow\Inject
6363
*/
6464
protected $workspaceRepository;
6565

6666
/**
67-
* @Flow\Inject
6867
* @var NodeIndexer
68+
* @Flow\Inject
6969
*/
7070
protected $nodeIndexer;
7171

@@ -77,30 +77,34 @@ class NodeIndexQueueCommandController extends CommandController
7777
public function buildCommand($workspace = null)
7878
{
7979
$indexPostfix = time();
80-
$this->createNextIndex($indexPostfix);
80+
$indexName = $this->createNextIndex($indexPostfix);
8181
$this->updateMapping();
8282

83+
$this->outputLine();
84+
$this->outputLine('<b>Indexing on %s ...</b>', [$indexName]);
8385

84-
$this->outputLine(sprintf('Indexing on %s ... ', $indexPostfix));
86+
$pendingJobs = $this->queueManager->getQueue(self::QUEUE_NAME)->count();
87+
if ($pendingJobs !== 0) {
88+
$this->outputLine('<error>!! </error> The queue "%s" is not empty (%d pending jobs), please flush the queue.', [self::QUEUE_NAME, $pendingJobs]);
89+
$this->quit(1);
90+
}
8591

8692
if ($workspace === null) {
8793
foreach ($this->workspaceRepository->findAll() as $workspace) {
8894
$workspace = $workspace->getName();
8995
$this->outputLine();
90-
$this->outputLine(sprintf('<info>++</info> Indexing %s workspace', $workspace));
9196
$this->indexWorkspace($workspace, $indexPostfix);
9297
}
9398
} else {
9499
$this->outputLine();
95-
$this->outputLine(sprintf('<info>++</info> Indexing only %s workspace', $workspace));
96100
$this->indexWorkspace($workspace, $indexPostfix);
97101
}
98102
$updateAliasJob = new UpdateAliasJob($indexPostfix);
99-
$queueName = 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer';
100-
$this->jobManager->queue($queueName, $updateAliasJob);
103+
$this->jobManager->queue(self::QUEUE_NAME, $updateAliasJob);
101104

105+
$this->outputLine("Indexing jobs created for queue %s with success ...", [self::QUEUE_NAME]);
106+
$this->outputSystemReport();
102107
$this->outputLine();
103-
$this->outputLine(sprintf('Indexing jobs created for queue %s with success ...', $queueName));
104108
}
105109

106110
/**

0 commit comments

Comments
 (0)