Commit 5105dc18 authored by Patrick Barroca's avatar Patrick Barroca 🐧

timeout management for http clients

parent 62817479
Pipeline #10499 passed with stage
in 45 seconds
......@@ -22,6 +22,10 @@ Import all sql files from database directory in filename order into mariadb.
Database connection is configured in conf/database.php, see conf/database.template.php.
### Http client options
Http client options are configured in conf/http_client.php see conf/http_client.template.php
## Dependencies handling
......
<?php
return ['timeout' => 2];
\ No newline at end of file
......@@ -4,6 +4,7 @@ use \Storm\Persistence\Mysqli\Connection;
use \Storm\Persistence\Configuration;
use \Storm\Model\Loader;
use \Storm\Persistence\SqlStrategy;
use \Pellicule\HttpClientAware;
require __DIR__ . '/../vendor/autoload.php';
......@@ -12,9 +13,13 @@ $app = \Pellicule\AppFactory::create();
$app->add(function($request, $handler)
{
$settings = require __DIR__ . '/../conf/database.php';
Connections::getInstance()->setDefault(new Connection(new Configuration($settings)));
Connections::getInstance()
->setDefault(new Connection(new Configuration($settings)));
Loader::defaultTo(SqlStrategy::class);
$settings = require __DIR__ . '/../conf/http_client.php';
HttpClientAware::setHttpClientOptions($settings);
return $handler->handle($request);
});
......
......@@ -8,13 +8,15 @@ use \Slim\Psr7\Factory\RequestFactory;
trait HttpClientAware {
protected static $_default_http_client;
protected static
$_default_http_client,
$_http_client_options;
static public function newHttpClient() {
if (static::$_default_http_client)
return static::$_default_http_client;
$client = new Curl(new ResponseFactory());
$client = new Curl(new ResponseFactory(), static::_httpClientOptions());
$browser = new Browser($client, new RequestFactory());
return $browser;
......@@ -24,4 +26,16 @@ trait HttpClientAware {
static public function setDefaultHttpClient($client) {
static::$_default_http_client = $client;
}
static public function setHttpClientOptions($options) {
static::$_http_client_options = $options;
}
static protected function _httpClientOptions() {
return static::$_http_client_options
? static::$_http_client_options
: [];
}
}
\ No newline at end of file
......@@ -41,8 +41,7 @@ class Electre extends Provider {
try {
$response = $this->_getToken($this->_client_id, $this->_client_secret);
} catch(\Exception $exception) {
return (new FetchRecordResult())->beError(StatusCodeInterface::STATUS_GATEWAY_TIMEOUT
,
return (new FetchRecordResult())->beError(StatusCodeInterface::STATUS_GATEWAY_TIMEOUT,
'no_answer_from_gateway');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment