Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure ElasticSearch index in esb.yml #37

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions src/Model/FlowConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,12 @@ public function getProducerBatchSize(): int
{
return $this->config['producer']['batch_size'];
}

/**
* @return array<array-key, mixed>|null
*/
public function getElasticSearchIndexCreateOrUpdateBody(): ?array
{
return $this->config['es_index'] ?? null;
}
}
8 changes: 8 additions & 0 deletions src/Service/ElasticSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ public function getClient(): Client
return $this->client;
}

/**
* @param array<array-key, mixed>|null $createOrUpdateBody
*/
public function setElasticSearchIndex(string $indexName, array $createOrUpdateBody = null): Amp\Promise
{
return $this->client->createOrUpdateIndex($indexName, $createOrUpdateBody);
mmenozzi marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @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
Loading