Skip to content
Snippets Groups Projects
Commit 6edd04cf authored by Mateusz Charytoniuk's avatar Mateusz Charytoniuk
Browse files

chore: add pool preconnect option

parent d9328fa7
Branches
Tags
No related merge requests found
......@@ -20,6 +20,8 @@ readonly class DatabaseConnectionPoolConfiguration
#[SensitiveParameter]
public string $password,
#[SensitiveParameter]
public bool $poolPrefill,
#[SensitiveParameter]
public int $poolSize,
#[SensitiveParameter]
public int $port,
......
......@@ -13,6 +13,7 @@ use ReflectionClass;
use ReflectionFunction;
use RuntimeException;
use Swoole\Coroutine\WaitGroup;
use Throwable;
use function Swoole\Coroutine\run;
......@@ -260,10 +261,17 @@ readonly class DependencyInjectionContainer
return $this->singletons->get($className);
}
$singleton = $this->doMakeSingleton($className, $previous);
try {
$singleton = $this->doMakeSingleton($className, $previous);
$this->singletons->set($className, $singleton);
$this->singletons->set($className, $singleton);
return $singleton;
return $singleton;
} catch (Throwable $throwable) {
throw new LogicException(
message: 'Error while building: '.$className,
previous: $throwable,
);
}
}
}
......@@ -16,6 +16,8 @@ readonly class RedisConnectionPoolConfiguration
#[SensitiveParameter]
public string $password,
#[SensitiveParameter]
public bool $poolPrefill,
#[SensitiveParameter]
public int $poolSize,
#[SensitiveParameter]
public int $port,
......
......@@ -20,6 +20,7 @@ use Nette\Schema\Schema;
* host: string,
* log_queries: bool,
* password: string,
* pool_prefill: bool,
* pool_size: int,
* port: int,
* username: string,
......@@ -44,6 +45,7 @@ final readonly class DatabaseConfigurationProvider extends ConfigurationProvider
'host' => Expect::string()->min(1)->required(),
'log_queries' => Expect::bool()->required(),
'password' => Expect::string()->required(),
'pool_prefill' => Expect::bool()->required(),
'pool_size' => Expect::int()->min(1)->required(),
'port' => Expect::int()->min(1)->max(65535)->required(),
'username' => Expect::string()->min(1)->required(),
......@@ -65,6 +67,7 @@ final readonly class DatabaseConfigurationProvider extends ConfigurationProvider
host: $connectionPoolConfiguration->host,
logQueries: $connectionPoolConfiguration->log_queries,
password: $connectionPoolConfiguration->password,
poolPrefill: $connectionPoolConfiguration->pool_prefill,
poolSize: $connectionPoolConfiguration->pool_size,
port: $connectionPoolConfiguration->port,
username: $connectionPoolConfiguration->username,
......
......@@ -18,6 +18,7 @@ use Nette\Schema\Schema;
* db_index: int,
* host: string,
* password: string,
* pool_prefill: bool,
* pool_size: int,
* port: int,
* prefix: string,
......@@ -41,6 +42,7 @@ final readonly class RedisConfigurationProvider extends ConfigurationProvider
'db_index' => Expect::int()->min(0)->required(),
'host' => Expect::string()->min(1)->required(),
'password' => Expect::string()->required(),
'pool_prefill' => Expect::bool()->required(),
'pool_size' => Expect::int()->min(1)->required(),
'port' => Expect::int()->min(1)->max(65535)->required(),
'prefix' => Expect::string()->min(1)->required(),
......@@ -61,6 +63,7 @@ final readonly class RedisConfigurationProvider extends ConfigurationProvider
dbIndex: $connectionPoolConfiguration->db_index,
host: $connectionPoolConfiguration->host,
password: $connectionPoolConfiguration->password,
poolPrefill: $connectionPoolConfiguration->pool_prefill,
poolSize: $connectionPoolConfiguration->pool_size,
port: $connectionPoolConfiguration->port,
prefix: $connectionPoolConfiguration->prefix,
......
......@@ -48,7 +48,10 @@ final readonly class DatabaseConnectionPoolRepositoryProvider extends SingletonP
;
$pdoPool = new PDOPool($pdoConfig, $connectionPoolConfiguration->poolSize);
$pdoPool->fill();
if ($connectionPoolConfiguration->poolPrefill) {
$pdoPool->fill();
}
$databaseConnectionPoolRepository->databaseConnectionPool->put($name, $pdoPool);
}
......
......@@ -39,7 +39,10 @@ final readonly class RedisConnectionPoolRepositoryProvider extends SingletonProv
;
$redisPool = new RedisPool($redisConfig, $connectionPoolConfiguration->poolSize);
$redisPool->fill();
if ($connectionPoolConfiguration->poolPrefill) {
$redisPool->fill();
}
$redisConnectionPoolRepository->redisConnectionPool->put($name, $redisPool);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment