Skip to content

Commit

Permalink
Allow to configure ElasticSearch index in esb.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
mmenozzi committed Oct 28, 2024
1 parent b5dc7ae commit df347d5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions esb.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ services:
flows:
sample_flow: # The flow "code" and will be the Beanstalkd tube name
description: Sample Flow # The flow description
es_index: # Optional: the create/update ElasticSearch index API body (see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html). This is useful if you want to control index mapping, settings and aliases.
settings: # For example you can set the total_fields limit to an higher (or lower) value:
index:
total_fields:
limit: 2000
producer:
service: My\Esb\Producer # A producer service ID defined above
batch_size: 1200 # Jobs are produced in batches of 1200 jobs. Optional: default is 1000
Expand Down
1 change: 1 addition & 0 deletions src/FlowConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->arrayPrototype()
->children()
->scalarNode('description')->isRequired()->cannotBeEmpty()->end()
->variableNode('es_index')->defaultNull()->end()
->arrayNode('producer')
->children()
->scalarNode('service')->isRequired()->end()
Expand Down
5 changes: 5 additions & 0 deletions src/Model/FlowConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,9 @@ public function getProducerBatchSize(): int
{
return $this->config['producer']['batch_size'];
}

public function getElasticSearchIndexCreateOrUpdateBody(): ?array

Check failure on line 106 in src/Model/FlowConfig.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Method Webgriffe\Esb\Model\FlowConfig::getElasticSearchIndexCreateOrUpdateBody() return type has no value type specified in iterable type array.

Check failure on line 106 in src/Model/FlowConfig.php

View workflow job for this annotation

GitHub Actions / PHP 8

Method Webgriffe\Esb\Model\FlowConfig::getElasticSearchIndexCreateOrUpdateBody() return type has no value type specified in iterable type array.
{
return $this->config['es_index'] ?? null;
}
}
5 changes: 5 additions & 0 deletions src/Service/ElasticSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public function getClient(): Client
return $this->client;
}

public function setElasticSearchIndex(string $indexName, array $createOrUpdateBody = null): Amp\Promise

Check failure on line 94 in src/Service/ElasticSearch.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Method Webgriffe\Esb\Service\ElasticSearch::setElasticSearchIndex() has parameter $createOrUpdateBody with no value type specified in iterable type array.

Check failure on line 94 in src/Service/ElasticSearch.php

View workflow job for this annotation

GitHub Actions / PHP 8

Method Webgriffe\Esb\Service\ElasticSearch::setElasticSearchIndex() has parameter $createOrUpdateBody with no value type specified in iterable type array.
{
return new Amp\Success();
}

/**
* @param JobInterface $job
* @param string $indexName
Expand Down
13 changes: 13 additions & 0 deletions src/Service/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ public function __construct(
public function boot(): Promise
{
return call(function () {
if ($this->flowConfig->getElasticSearchIndexCreateOrUpdateBody() !== null) {
yield $this->elasticSearch->setElasticSearchIndex(
$this->flowConfig->getTube(),
$this->flowConfig->getElasticSearchIndexCreateOrUpdateBody()
);
$this->logger->debug(
'Successfully set ElasticSearch index',
[
'index' => $this->flowConfig->getTube(),
'body' => $this->flowConfig->getElasticSearchIndexCreateOrUpdateBody()
]
);
}
//Producer
yield $this->beanstalkClient->use($this->flowConfig->getTube());

Expand Down

0 comments on commit df347d5

Please sign in to comment.