Skip to content

Commit 83e7255

Browse files
committed
Added request_timeout method for the connection and set the default to 300s
1 parent 510abef commit 83e7255

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

docs/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ sineflow_elasticsearch:
2626
profiling_backtrace: false
2727
logging: true
2828
bulk_batch_size: 1000
29+
request_timeout: 300
2930
3031
indices:
3132
_base:
@@ -81,6 +82,7 @@ And here is the breakdown:
8182
* `profiling` *(default: true)*: Enable or disable profiling. The default setup makes use of Elasticsearch client's profiling to gather information for the Symfony profiler toolbar, which is extremely useful in development.
8283
* `logging` *(default: true)*: When enabled, the bundle uses Symfony's 'logger' service to log Elasticsearch events in the 'sfes' channel. Using symfony/monolog-bundle, the logging can be easily controlled. For example the 'sfes' channel can be redirected to a rotating file log.
8384
* `bulk_batch_size` *(default: 1000)*: This is currently used only when using the **rebuildIndex()** method of the index manager.
85+
* `request_timeout` *(default: 300)*: The timeout for HTTP requests to Elasticsearch in seconds. This applies to all synchronous operations including reindex, bulk operations, and long-running queries. Increase this value if you have long-running operations that exceed the default timeout.
8486

8587
* `indices`: Here you define the Elasticsearch indexes you have. The key here is the name of the index manager, which determines how it will be accessible in the application. In the example above, we have an index manager named **products**, which would be accessible as **$container->get('sfes.index.products')**.
8688
It is important to note here the use of **'_'** in front of the index manager name. When defined like that, this will be an abstract definition, i.e. no manager will actually be created from that definition. This is very useful when you have common setting for several indices, as you can define a template for them all and not have to duplicate stuff.

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ private function getConnectionsNode(): NodeDefinition
137137
->defaultValue(1000)
138138
->info('The number of requests to send at once, when doing bulk operations')
139139
->end()
140+
->scalarNode('request_timeout')
141+
->defaultValue(300)
142+
->info('Timeout for HTTP requests to Elasticsearch in seconds (default: 300)')
143+
->end()
140144

141145
->end()
142146
->end();

src/Manager/ConnectionManager.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ public function getClient(): Client
107107
$clientBuilder->setSSLCert($this->connectionSettings['ssl_cert']);
108108
}
109109

110+
// Configure HTTP client timeout
111+
$httpClientOptions = [];
112+
if (isset($this->connectionSettings['request_timeout'])) {
113+
$httpClientOptions['timeout'] = $this->connectionSettings['request_timeout'];
114+
}
115+
if (!empty($httpClientOptions)) {
116+
$clientBuilder->setHttpClientOptions($httpClientOptions);
117+
}
118+
110119
if ($this->logger) {
111120
$clientBuilder->setLogger($this->logger);
112121
}

tests/Unit/DependencyInjection/ElasticsearchExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public static function getData()
118118
'ssl_ca' => null,
119119
'ssl_key' => null,
120120
'ssl_cert' => null,
121+
'request_timeout' => 300,
121122
],
122123
];
123124

tests/Unit/ElasticsearchBundleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testPassesRegistered(): void
4040
$finder = new Finder();
4141
$finder->files()->in(__DIR__.'/../../src/DependencyInjection/Compiler/');
4242

43-
/** @var $file SplFileInfo */
43+
/** @var SplFileInfo $file */
4444
foreach ($finder as $file) {
4545
$passName = \str_replace('.php', '', $file->getFilename());
4646
// Check whether pass is not blacklisted and not added by bundle.

0 commit comments

Comments
 (0)