2020-07-29 07:48:51 +12:00
|
|
|
<?php
|
2022-05-24 02:54:50 +12:00
|
|
|
|
|
|
|
require_once __DIR__ . '/init.php';
|
|
|
|
require_once __DIR__ . '/controllers/general.php';
|
2020-07-29 07:48:51 +12:00
|
|
|
|
2022-08-02 13:32:46 +12:00
|
|
|
use Appwrite\CLI\Tasks;
|
2022-10-28 16:36:20 +13:00
|
|
|
use Utopia\CLI\CLI;
|
2022-04-10 21:38:22 +12:00
|
|
|
use Utopia\Database\Validator\Authorization;
|
2022-08-02 13:32:46 +12:00
|
|
|
use Utopia\Platform\Service;
|
2022-10-28 16:36:20 +13:00
|
|
|
use Utopia\App;
|
|
|
|
use Utopia\CLI\Console;
|
|
|
|
use Utopia\Cache\Adapter\Redis as RedisCache;
|
|
|
|
use Utopia\Cache\Cache;
|
|
|
|
use Utopia\Database\Adapter\MariaDB;
|
|
|
|
use Utopia\Database\Database;
|
2022-04-10 21:38:22 +12:00
|
|
|
|
|
|
|
Authorization::disable();
|
2020-07-29 07:48:51 +12:00
|
|
|
|
2022-10-28 16:36:20 +13:00
|
|
|
CLI::setResource('register', fn()=>$register);
|
|
|
|
|
|
|
|
$attempts = 0;
|
|
|
|
$max = 10;
|
|
|
|
$sleep = 1;
|
|
|
|
|
|
|
|
do {
|
|
|
|
try {
|
|
|
|
$attempts++;
|
|
|
|
$db = $register->get('db');
|
|
|
|
$redis = $register->get('cache');
|
|
|
|
break; // leave the do-while if successful
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Console::warning("Database not ready. Retrying connection ({$attempts})...");
|
|
|
|
if ($attempts >= $max) {
|
|
|
|
throw new \Exception('Failed to connect to database: ' . $e->getMessage());
|
|
|
|
}
|
|
|
|
sleep($sleep);
|
|
|
|
}
|
|
|
|
} while ($attempts < $max);
|
|
|
|
|
|
|
|
CLI::setResource('db', fn () => $db);
|
|
|
|
CLI::setResource('cache', fn () => $redis);
|
|
|
|
|
|
|
|
CLI::setResource('dbForConsole', function ($db, $cache) {
|
|
|
|
$cache = new Cache(new RedisCache($cache));
|
|
|
|
|
|
|
|
$database = new Database(new MariaDB($db), $cache);
|
|
|
|
$database->setDefaultDatabase(App::getEnv('_APP_DB_SCHEMA', 'appwrite'));
|
|
|
|
$database->setNamespace('_console');
|
|
|
|
|
|
|
|
return $database;
|
|
|
|
}, ['db', 'cache']);
|
|
|
|
|
2022-10-28 17:09:34 +13:00
|
|
|
/** @var InfluxDB\Client $client */
|
|
|
|
$client = $register->get('influxdb');
|
|
|
|
$attempts = 0;
|
|
|
|
$max = 10;
|
|
|
|
$sleep = 1;
|
|
|
|
|
|
|
|
do { // check if telegraf database is ready
|
|
|
|
try {
|
|
|
|
$attempts++;
|
|
|
|
$database = $client->selectDB('telegraf');
|
|
|
|
if (in_array('telegraf', $client->listDatabases())) {
|
|
|
|
break; // leave the do-while if successful
|
|
|
|
}
|
|
|
|
} catch (\Throwable$th) {
|
|
|
|
Console::warning("InfluxDB not ready. Retrying connection ({$attempts})...");
|
|
|
|
if ($attempts >= $max) {
|
|
|
|
throw new \Exception('InfluxDB database not ready yet');
|
|
|
|
}
|
|
|
|
sleep($sleep);
|
|
|
|
}
|
|
|
|
} while ($attempts < $max);
|
|
|
|
CLI::setResource('influxdb', fn() => $database);
|
|
|
|
|
2022-08-02 13:32:46 +12:00
|
|
|
$cliPlatform = new Tasks();
|
|
|
|
$cliPlatform->init(Service::TYPE_CLI);
|
2022-07-13 18:26:22 +12:00
|
|
|
|
|
|
|
$cli = $cliPlatform->getCli();
|
|
|
|
$cli->run();
|