Fixed linter errors
This commit is contained in:
parent
4fe5c0dd1d
commit
d51c379514
7 changed files with 80 additions and 81 deletions
|
@ -45,7 +45,7 @@ function getConsoleDB(): Database
|
|||
global $register;
|
||||
|
||||
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
|
||||
|
||||
|
||||
$dbAdapter = $pools
|
||||
->get('console')
|
||||
->pop()
|
||||
|
@ -65,10 +65,10 @@ function getCache(): Cache
|
|||
global $register;
|
||||
|
||||
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
|
||||
|
||||
|
||||
$list = Config::getParam('pools-cache', []);
|
||||
$adapters = [];
|
||||
|
||||
|
||||
foreach ($list as $value) {
|
||||
$adapters[] = $pools
|
||||
->get($value)
|
||||
|
@ -103,7 +103,7 @@ $cli
|
|||
|
||||
$cli
|
||||
->error(function ($error) {
|
||||
if(App::getEnv('_APP_ENV', 'development')) {
|
||||
if (App::getEnv('_APP_ENV', 'development')) {
|
||||
Console::error($error);
|
||||
} else {
|
||||
Console::error($error->getMessage());
|
||||
|
|
|
@ -76,23 +76,23 @@ App::get('/v1/health/db')
|
|||
$adapter = $pools->get($database)->pop()->getResource();
|
||||
|
||||
$checkStart = \microtime(true);
|
||||
|
||||
if($adapter->ping()) {
|
||||
|
||||
if ($adapter->ping()) {
|
||||
$output[] = new Document([
|
||||
'name' => $key." ($database)",
|
||||
'name' => $key . " ($database)",
|
||||
'status' => 'pass',
|
||||
'ping' => \round((\microtime(true) - $checkStart) / 1000)
|
||||
]);
|
||||
} else {
|
||||
$output[] = new Document([
|
||||
'name' => $key." ($database)",
|
||||
'name' => $key . " ($database)",
|
||||
'status' => 'fail',
|
||||
'ping' => \round((\microtime(true) - $checkStart) / 1000)
|
||||
]);
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
$output[] = new Document([
|
||||
'name' => $key." ($database)",
|
||||
'name' => $key . " ($database)",
|
||||
'status' => 'fail',
|
||||
'ping' => \round((\microtime(true) - $checkStart) / 1000)
|
||||
]);
|
||||
|
@ -133,23 +133,23 @@ App::get('/v1/health/cache')
|
|||
$adapter = $pools->get($database)->pop()->getResource();
|
||||
|
||||
$checkStart = \microtime(true);
|
||||
|
||||
if($adapter->ping()) {
|
||||
|
||||
if ($adapter->ping()) {
|
||||
$output[] = new Document([
|
||||
'name' => $key." ($database)",
|
||||
'name' => $key . " ($database)",
|
||||
'status' => 'pass',
|
||||
'ping' => \round((\microtime(true) - $checkStart) / 1000)
|
||||
]);
|
||||
} else {
|
||||
$output[] = new Document([
|
||||
'name' => $key." ($database)",
|
||||
'name' => $key . " ($database)",
|
||||
'status' => 'fail',
|
||||
'ping' => \round((\microtime(true) - $checkStart) / 1000)
|
||||
]);
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
$output[] = new Document([
|
||||
'name' => $key." ($database)",
|
||||
'name' => $key . " ($database)",
|
||||
'status' => 'fail',
|
||||
'ping' => \round((\microtime(true) - $checkStart) / 1000)
|
||||
]);
|
||||
|
@ -190,23 +190,23 @@ App::get('/v1/health/queue')
|
|||
$adapter = $pools->get($database)->pop()->getResource();
|
||||
|
||||
$checkStart = \microtime(true);
|
||||
|
||||
if($adapter->ping()) {
|
||||
|
||||
if ($adapter->ping()) {
|
||||
$output[] = new Document([
|
||||
'name' => $key." ($database)",
|
||||
'name' => $key . " ($database)",
|
||||
'status' => 'pass',
|
||||
'ping' => \round((\microtime(true) - $checkStart) / 1000)
|
||||
]);
|
||||
} else {
|
||||
$output[] = new Document([
|
||||
'name' => $key." ($database)",
|
||||
'name' => $key . " ($database)",
|
||||
'status' => 'fail',
|
||||
'ping' => \round((\microtime(true) - $checkStart) / 1000)
|
||||
]);
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
$output[] = new Document([
|
||||
'name' => $key." ($database)",
|
||||
'name' => $key . " ($database)",
|
||||
'status' => 'fail',
|
||||
'ping' => \round((\microtime(true) - $checkStart) / 1000)
|
||||
]);
|
||||
|
@ -247,23 +247,23 @@ App::get('/v1/health/pubsub')
|
|||
$adapter = $pools->get($database)->pop()->getResource();
|
||||
|
||||
$checkStart = \microtime(true);
|
||||
|
||||
if($adapter->ping()) {
|
||||
|
||||
if ($adapter->ping()) {
|
||||
$output[] = new Document([
|
||||
'name' => $key." ($database)",
|
||||
'name' => $key . " ($database)",
|
||||
'status' => 'pass',
|
||||
'ping' => \round((\microtime(true) - $checkStart) / 1000)
|
||||
]);
|
||||
} else {
|
||||
$output[] = new Document([
|
||||
'name' => $key." ($database)",
|
||||
'name' => $key . " ($database)",
|
||||
'status' => 'fail',
|
||||
'ping' => \round((\microtime(true) - $checkStart) / 1000)
|
||||
]);
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
$output[] = new Document([
|
||||
'name' => $key." ($database)",
|
||||
'name' => $key . " ($database)",
|
||||
'status' => 'fail',
|
||||
'ping' => \round((\microtime(true) - $checkStart) / 1000)
|
||||
]);
|
||||
|
|
|
@ -75,7 +75,7 @@ App::post('/v1/projects')
|
|||
->inject('pools')
|
||||
->action(function (string $projectId, string $name, string $teamId, string $description, string $logo, string $url, string $legalName, string $legalCountry, string $legalState, string $legalCity, string $legalAddress, string $legalTaxId, Response $response, Database $dbForConsole, Cache $cache, Group $pools) {
|
||||
|
||||
|
||||
|
||||
$team = $dbForConsole->getDocument('teams', $teamId);
|
||||
|
||||
if ($team->isEmpty()) {
|
||||
|
|
40
app/init.php
40
app/init.php
|
@ -499,7 +499,7 @@ $register->set('logger', function () {
|
|||
});
|
||||
$register->set('pools', function () {
|
||||
|
||||
$group= new Group();
|
||||
$group = new Group();
|
||||
|
||||
$fallbackForDB = URLURL::unparse([
|
||||
'scheme' => 'mariadb',
|
||||
|
@ -556,14 +556,14 @@ $register->set('pools', function () {
|
|||
$schemes = $connection['schemes'] ?? [];
|
||||
$config = [];
|
||||
$dsns = explode(',', $connection['dsns'] ?? '');
|
||||
|
||||
|
||||
foreach ($dsns as &$dsn) {
|
||||
$dsn = explode('=', $dsn);
|
||||
$name = ($multipe) ? $key.'_'.$dsn[0] : $key;
|
||||
$name = ($multipe) ? $key . '_' . $dsn[0] : $key;
|
||||
$dsn = $dsn[1] ?? '';
|
||||
$config[] = $name;
|
||||
|
||||
if(empty($dsn)) {
|
||||
if (empty($dsn)) {
|
||||
//throw new Exception(Exception::GENERAL_SERVER_ERROR, "Missing value for DSN connection in {$key}");
|
||||
continue;
|
||||
}
|
||||
|
@ -575,15 +575,15 @@ $register->set('pools', function () {
|
|||
$dsnPass = $dsn->getPassword();
|
||||
$dsnScheme = $dsn->getDatabase();
|
||||
|
||||
if(!in_array($dsn->getScheme(), $schemes)) {
|
||||
if (!in_array($dsn->getScheme(), $schemes)) {
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, "Invalid console database scheme");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Resource
|
||||
*
|
||||
*
|
||||
* Creation could be reused accross connection types like database, cache, queue, etc.
|
||||
*
|
||||
*
|
||||
* Resource assignment to an adapter will happen below.
|
||||
*/
|
||||
|
||||
|
@ -591,7 +591,7 @@ $register->set('pools', function () {
|
|||
case 'mysql':
|
||||
case 'mariadb':
|
||||
$resource = function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnScheme) {
|
||||
return new PDOProxy(function() use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnScheme) {
|
||||
return new PDOProxy(function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnScheme) {
|
||||
return new PDO("mysql:host={$dsnHost};port={$dsnPort};dbname={$dsnScheme};charset=utf8mb4", $dsnUser, $dsnPass, array(
|
||||
PDO::ATTR_TIMEOUT => 3, // Seconds
|
||||
PDO::ATTR_PERSISTENT => true,
|
||||
|
@ -604,18 +604,18 @@ $register->set('pools', function () {
|
|||
};
|
||||
break;
|
||||
case 'redis':
|
||||
$resource = function() use ($dsnHost, $dsnPort, $dsnPass) {
|
||||
$resource = function () use ($dsnHost, $dsnPort, $dsnPass) {
|
||||
$redis = new Redis();
|
||||
@$redis->pconnect($dsnHost, (int)$dsnPort);
|
||||
if($dsnPass) {
|
||||
if ($dsnPass) {
|
||||
$redis->auth($dsnPass);
|
||||
}
|
||||
$redis->setOption(Redis::OPT_READ_TIMEOUT, -1);
|
||||
|
||||
|
||||
return $redis;
|
||||
};
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, "Invalid scheme");
|
||||
break;
|
||||
|
@ -632,7 +632,7 @@ $register->set('pools', function () {
|
|||
'mysql' => new MySQL($resource()),
|
||||
default => null
|
||||
};
|
||||
|
||||
|
||||
break;
|
||||
case 'queue':
|
||||
$adapter = $resource();
|
||||
|
@ -646,25 +646,25 @@ $register->set('pools', function () {
|
|||
default => null
|
||||
};
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, "Server error: Missing adapter implementation.");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return $adapter;
|
||||
});
|
||||
|
||||
$group->add($pool);
|
||||
}
|
||||
|
||||
Config::setParam('pools-'.$key, $config);
|
||||
Config::setParam('pools-' . $key, $config);
|
||||
}
|
||||
|
||||
try {
|
||||
$group->fill();
|
||||
} catch (\Throwable $th) {
|
||||
Console::error('Connection failure: '.$th->getMessage());
|
||||
Console::error('Connection failure: ' . $th->getMessage());
|
||||
}
|
||||
|
||||
return $group;
|
||||
|
@ -1022,7 +1022,7 @@ App::setResource('console', function () {
|
|||
}, []);
|
||||
|
||||
App::setResource('dbForProject', function (Group $pools, Database $dbForConsole, Cache $cache, Document $project) {
|
||||
if($project->isEmpty() || $project->getId() === 'console') {
|
||||
if ($project->isEmpty() || $project->getId() === 'console') {
|
||||
return $dbForConsole;
|
||||
}
|
||||
|
||||
|
@ -1033,7 +1033,7 @@ App::setResource('dbForProject', function (Group $pools, Database $dbForConsole,
|
|||
;
|
||||
|
||||
$database = new Database($dbAdapter, $cache);
|
||||
$database->setNamespace('_'.$project->getInternalId());
|
||||
$database->setNamespace('_' . $project->getInternalId());
|
||||
$database->setDefaultDatabase('appwrite');
|
||||
|
||||
return $database;
|
||||
|
@ -1057,7 +1057,7 @@ App::setResource('dbForConsole', function (Group $pools, Cache $cache) {
|
|||
App::setResource('cache', function (Group $pools) {
|
||||
$list = Config::getParam('pools-cache', []);
|
||||
$adapters = [];
|
||||
|
||||
|
||||
foreach ($list as $value) {
|
||||
$adapters[] = $pools
|
||||
->get($value)
|
||||
|
|
|
@ -38,7 +38,7 @@ function getConsoleDB(): Database
|
|||
global $register;
|
||||
|
||||
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
|
||||
|
||||
|
||||
$dbAdapter = $pools
|
||||
->get('console')
|
||||
->pop()
|
||||
|
@ -59,7 +59,7 @@ function getProjectDB(Document $project): Database
|
|||
|
||||
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
|
||||
|
||||
if($project->isEmpty() || $project->getId() === 'console') {
|
||||
if ($project->isEmpty() || $project->getId() === 'console') {
|
||||
return getConsoleDB();
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ function getProjectDB(Document $project): Database
|
|||
;
|
||||
|
||||
$database = new Database($dbAdapter, getCache());
|
||||
$database->setNamespace('_'.$project->getInternalId());
|
||||
$database->setNamespace('_' . $project->getInternalId());
|
||||
$database->setDefaultDatabase('appwrite');
|
||||
|
||||
return $database;
|
||||
|
@ -81,10 +81,10 @@ function getCache(): Cache
|
|||
global $register;
|
||||
|
||||
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
|
||||
|
||||
|
||||
$list = Config::getParam('pools-cache', []);
|
||||
$adapters = [];
|
||||
|
||||
|
||||
foreach ($list as $value) {
|
||||
$adapters[] = $pools
|
||||
->get($value)
|
||||
|
@ -168,7 +168,7 @@ $server->onStart(function () use ($stats, $register, $containerId, &$statsDocume
|
|||
go(function () use ($register, $containerId, &$statsDocument) {
|
||||
$attempts = 0;
|
||||
$database = getConsoleDB();
|
||||
|
||||
|
||||
do {
|
||||
try {
|
||||
$attempts++;
|
||||
|
@ -338,7 +338,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats,
|
|||
$roles = Auth::getRoles($user);
|
||||
|
||||
$realtime->subscribe($projectId, $connection, $roles, $realtime->connections[$connection]['channels']);
|
||||
|
||||
|
||||
$register->get('pools')->reclaim();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,13 +107,13 @@ $cli
|
|||
try {
|
||||
$adapter = $pools->get($database)->pop()->getResource();
|
||||
|
||||
if($adapter->ping()) {
|
||||
Console::success('🟢 '.str_pad("{$key}({$database})", 50, '.').'connected');
|
||||
if ($adapter->ping()) {
|
||||
Console::success('🟢 ' . str_pad("{$key}({$database})", 50, '.') . 'connected');
|
||||
} else {
|
||||
Console::error('🔴 '.str_pad("{$key}({$database})", 47, '.').'disconnected');
|
||||
Console::error('🔴 ' . str_pad("{$key}({$database})", 47, '.') . 'disconnected');
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
Console::error('🔴 '.str_pad("{$key}.({$database})", 47, '.').'disconnected');
|
||||
Console::error('🔴 ' . str_pad("{$key}.({$database})", 47, '.') . 'disconnected');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,13 +130,13 @@ $cli
|
|||
try {
|
||||
$adapter = $pools->get($pool)->pop()->getResource();
|
||||
|
||||
if($adapter->ping()) {
|
||||
Console::success('🟢 '.str_pad("{$key}({$pool})", 50, '.').'connected');
|
||||
if ($adapter->ping()) {
|
||||
Console::success('🟢 ' . str_pad("{$key}({$pool})", 50, '.') . 'connected');
|
||||
} else {
|
||||
Console::error('🔴 '.str_pad("{$key}({$pool})", 47, '.').'disconnected');
|
||||
Console::error('🔴 ' . str_pad("{$key}({$pool})", 47, '.') . 'disconnected');
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
Console::error('🔴 '.str_pad("{$key}({$pool})", 47, '.').'disconnected');
|
||||
Console::error('🔴 ' . str_pad("{$key}({$pool})", 47, '.') . 'disconnected');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,12 +149,12 @@ $cli
|
|||
);
|
||||
|
||||
if ((@$antivirus->ping())) {
|
||||
Console::success('🟢 '.str_pad("Antivirus", 50, '.').'connected');
|
||||
Console::success('🟢 ' . str_pad("Antivirus", 50, '.') . 'connected');
|
||||
} else {
|
||||
Console::error('🔴 '.str_pad("Antivirus", 47, '.').'disconnected');
|
||||
Console::error('🔴 ' . str_pad("Antivirus", 47, '.') . 'disconnected');
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
Console::error('🔴 '.str_pad("Antivirus", 47, '.').'disconnected');
|
||||
Console::error('🔴 ' . str_pad("Antivirus", 47, '.') . 'disconnected');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,29 +167,29 @@ $cli
|
|||
$mail->AltBody = 'Hello World';
|
||||
|
||||
$mail->send();
|
||||
Console::success('🟢 '.str_pad("SMTP", 50, '.').'connected');
|
||||
Console::success('🟢 ' . str_pad("SMTP", 50, '.') . 'connected');
|
||||
} catch (\Throwable $th) {
|
||||
Console::error('🔴 '.str_pad("SMTP", 47, '.').'disconnected');
|
||||
Console::error('🔴 ' . str_pad("SMTP", 47, '.') . 'disconnected');
|
||||
}
|
||||
|
||||
$host = App::getEnv('_APP_STATSD_HOST', 'telegraf');
|
||||
$port = App::getEnv('_APP_STATSD_PORT', 8125);
|
||||
|
||||
if ($fp = @\fsockopen('udp://' . $host, $port, $errCode, $errStr, 2)) {
|
||||
Console::success('🟢 '.str_pad("StatsD", 50, '.').'connected');
|
||||
Console::success('🟢 ' . str_pad("StatsD", 50, '.') . 'connected');
|
||||
\fclose($fp);
|
||||
} else {
|
||||
Console::error('🔴 '.str_pad("StatsD", 47, '.').'disconnected');
|
||||
Console::error('🔴 ' . str_pad("StatsD", 47, '.') . 'disconnected');
|
||||
}
|
||||
|
||||
$host = App::getEnv('_APP_INFLUXDB_HOST', '');
|
||||
$port = App::getEnv('_APP_INFLUXDB_PORT', '');
|
||||
|
||||
if ($fp = @\fsockopen($host, $port, $errCode, $errStr, 2)) {
|
||||
Console::success('🟢 '.str_pad("InfluxDB", 50, '.').'connected');
|
||||
Console::success('🟢 ' . str_pad("InfluxDB", 50, '.') . 'connected');
|
||||
\fclose($fp);
|
||||
} else {
|
||||
Console::error('🔴 '.str_pad("InfluxDB", 47, '.').'disconnected');
|
||||
Console::error('🔴 ' . str_pad("InfluxDB", 47, '.') . 'disconnected');
|
||||
}
|
||||
|
||||
\sleep(0.2);
|
||||
|
|
|
@ -141,9 +141,8 @@ abstract class Worker
|
|||
try {
|
||||
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
|
||||
$pools->reclaim();
|
||||
|
||||
$this->shutdown();
|
||||
|
||||
$this->shutdown();
|
||||
} catch (\Throwable $error) {
|
||||
foreach (self::$errorCallbacks as $errorCallback) {
|
||||
$errorCallback($error, "shutdown", $this->getName());
|
||||
|
@ -176,20 +175,20 @@ abstract class Worker
|
|||
|
||||
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
|
||||
|
||||
if($project->isEmpty() || $project->getId() === 'console') {
|
||||
if ($project->isEmpty() || $project->getId() === 'console') {
|
||||
return $this->getConsoleDB();
|
||||
}
|
||||
|
||||
|
||||
$dbAdapter = $pools
|
||||
->get($project->getAttribute('database'))
|
||||
->pop()
|
||||
->getResource()
|
||||
;
|
||||
|
||||
|
||||
$database = new Database($dbAdapter, $this->getCache());
|
||||
$database->setNamespace('_'.$project->getInternalId());
|
||||
$database->setNamespace('_' . $project->getInternalId());
|
||||
$database->setDefaultDatabase('appwrite');
|
||||
|
||||
|
||||
return $database;
|
||||
}
|
||||
|
||||
|
@ -202,7 +201,7 @@ abstract class Worker
|
|||
global $register;
|
||||
|
||||
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
|
||||
|
||||
|
||||
$dbAdapter = $pools
|
||||
->get('console')
|
||||
->pop()
|
||||
|
@ -217,7 +216,7 @@ abstract class Worker
|
|||
return $database;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Cache
|
||||
* @return Cache
|
||||
|
@ -227,10 +226,10 @@ abstract class Worker
|
|||
global $register;
|
||||
|
||||
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
|
||||
|
||||
|
||||
$list = Config::getParam('pools-cache', []);
|
||||
$adapters = [];
|
||||
|
||||
|
||||
foreach ($list as $value) {
|
||||
$adapters[] = $pools
|
||||
->get($value)
|
||||
|
@ -238,7 +237,7 @@ abstract class Worker
|
|||
->getResource()
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
return new Cache(new Sharding($adapters));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue