Skip to content

Commit

Permalink
Merge branch 'master' into php83-support
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppemorelli committed Nov 7, 2024
2 parents c08d4d1 + 4dac01b commit 159caf5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"php": "~7.4.0|~8.0.0|~8.1.0|~8.2.0|~8.3.0",
"ext-pcntl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"symfony/dependency-injection": "^4.3",
"symfony/config": "^4.3",
"symfony/yaml": "^4.3",
Expand All @@ -33,7 +34,7 @@
"symfony/property-info": "^4.3",
"doctrine/annotations": "^1.8",
"ramsey/uuid": "^3.8",
"webgriffe/amp-elasticsearch": "dev-php8-support as 2.1",
"webgriffe/amp-elasticsearch": "^2.1",
"pagerfanta/pagerfanta": "^2.4",
"symfony/deprecation-contracts": "^2.1",
"amphp/http-server-form-parser": "^1.1"
Expand Down
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);
}

/**
* @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 159caf5

Please sign in to comment.