refactor case
This commit is contained in:
parent
d688187e23
commit
3d25ef1be5
1 changed files with 47 additions and 33 deletions
|
@ -114,18 +114,9 @@ $logError = function (Throwable $error, string $action = 'syncUsageStats') use (
|
||||||
Console::warning($error->getTraceAsString());
|
Console::warning($error->getTraceAsString());
|
||||||
};
|
};
|
||||||
|
|
||||||
$cli
|
|
||||||
->task('usage')
|
|
||||||
->param('type', 'timeseries', new WhiteList(['timeseries', 'database']))
|
|
||||||
->desc('Schedules syncing data from influxdb to Appwrite console db')
|
|
||||||
->action(function (string $type) use ($register, $logError) {
|
|
||||||
Console::title('Usage Aggregation V1');
|
|
||||||
Console::success(APP_NAME . ' usage aggregation process v1 has started');
|
|
||||||
|
|
||||||
$database = getDatabase($register, '_console');
|
function aggregateTimeseries(UtopiaDatabase $database, InfluxDatabase $influxDB, callable $logError): void
|
||||||
$influxDB = getInfluxDB($register);
|
{
|
||||||
|
|
||||||
if ($type == 'timeseries') {
|
|
||||||
$interval = (int) App::getEnv('_APP_USAGE_TIMESERIES_INTERVAL', '30'); // 30 seconds (by default)
|
$interval = (int) App::getEnv('_APP_USAGE_TIMESERIES_INTERVAL', '30'); // 30 seconds (by default)
|
||||||
$usage = new TimeSeries($database, $influxDB, $logError);
|
$usage = new TimeSeries($database, $influxDB, $logError);
|
||||||
|
|
||||||
|
@ -142,7 +133,8 @@ $cli
|
||||||
}, $interval);
|
}, $interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type == 'database') {
|
function aggregateDatabase(UtopiaDatabase $database, callable $logError): void
|
||||||
|
{
|
||||||
$interval = (int) App::getEnv('_APP_USAGE_DATABASE_INTERVAL', '900'); // 15 minutes (by default)
|
$interval = (int) App::getEnv('_APP_USAGE_DATABASE_INTERVAL', '900'); // 15 minutes (by default)
|
||||||
$usage = new Database($database, $logError);
|
$usage = new Database($database, $logError);
|
||||||
$aggregrator = new Aggregator($database, $logError);
|
$aggregrator = new Aggregator($database, $logError);
|
||||||
|
@ -159,4 +151,26 @@ $cli
|
||||||
Console::info("[{$now}] Aggregation took {$loopTook} seconds");
|
Console::info("[{$now}] Aggregation took {$loopTook} seconds");
|
||||||
}, $interval);
|
}, $interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cli
|
||||||
|
->task('usage')
|
||||||
|
->param('type', 'timeseries', new WhiteList(['timeseries', 'database']))
|
||||||
|
->desc('Schedules syncing data from influxdb to Appwrite console db')
|
||||||
|
->action(function (string $type) use ($register, $logError) {
|
||||||
|
Console::title('Usage Aggregation V1');
|
||||||
|
Console::success(APP_NAME . ' usage aggregation process v1 has started');
|
||||||
|
|
||||||
|
$database = getDatabase($register, '_console');
|
||||||
|
$influxDB = getInfluxDB($register);
|
||||||
|
|
||||||
|
switch($type) {
|
||||||
|
case 'timeseries':
|
||||||
|
aggregateTimeseries($database, $influxDB, $logError);
|
||||||
|
break;
|
||||||
|
case 'database':
|
||||||
|
aggregateDatabase($database, $logError);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Console::error("Unsupported usage aggregation type");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue