pass region in constructors
This commit is contained in:
parent
651ccef328
commit
8c6ef5b26f
|
@ -118,7 +118,8 @@ $logError = function (Throwable $error, string $action = 'syncUsageStats') use (
|
|||
function aggregateTimeseries(UtopiaDatabase $database, InfluxDatabase $influxDB, callable $logError): void
|
||||
{
|
||||
$interval = (int) App::getEnv('_APP_USAGE_TIMESERIES_INTERVAL', '30'); // 30 seconds (by default)
|
||||
$usage = new TimeSeries($database, $influxDB, $logError);
|
||||
$region = App::getEnv('region', 'default');
|
||||
$usage = new TimeSeries($region, $database, $influxDB, $logError);
|
||||
|
||||
Console::loop(function () use ($interval, $usage) {
|
||||
$now = date('d-m-Y H:i:s', time());
|
||||
|
@ -136,8 +137,9 @@ function aggregateTimeseries(UtopiaDatabase $database, InfluxDatabase $influxDB,
|
|||
function aggregateDatabase(UtopiaDatabase $database, callable $logError): void
|
||||
{
|
||||
$interval = (int) App::getEnv('_APP_USAGE_DATABASE_INTERVAL', '900'); // 15 minutes (by default)
|
||||
$usage = new Database($database, $logError);
|
||||
$aggregrator = new Aggregator($database, $logError);
|
||||
$region = App::getEnv('region', 'default');
|
||||
$usage = new Database($region, $database, $logError);
|
||||
$aggregrator = new Aggregator($region, $database, $logError);
|
||||
|
||||
Console::loop(function () use ($interval, $usage, $aggregrator) {
|
||||
$now = date('d-m-Y H:i:s', time());
|
||||
|
|
|
@ -4,5 +4,12 @@ namespace Appwrite\Usage;
|
|||
|
||||
abstract class Calculator
|
||||
{
|
||||
protected string $region;
|
||||
|
||||
public function __construct(string $region)
|
||||
{
|
||||
$this->region = $region;
|
||||
}
|
||||
|
||||
abstract public function collect(): void;
|
||||
}
|
||||
|
|
|
@ -25,8 +25,9 @@ class Database extends Calculator
|
|||
],
|
||||
];
|
||||
|
||||
public function __construct(UtopiaDatabase $database, callable $errorHandler = null)
|
||||
public function __construct(string $region, UtopiaDatabase $database, callable $errorHandler = null)
|
||||
{
|
||||
parent::__construct($region);
|
||||
$this->database = $database;
|
||||
$this->errorHandler = $errorHandler;
|
||||
}
|
||||
|
@ -96,7 +97,7 @@ class Database extends Calculator
|
|||
'time' => $time,
|
||||
'metric' => $metric,
|
||||
'value' => $value,
|
||||
'region' => App::getEnv('_APP_REGION', 'default'),
|
||||
'region' => $this->region,
|
||||
'type' => 2, // these are cumulative metrics
|
||||
]));
|
||||
} else {
|
||||
|
|
|
@ -279,8 +279,9 @@ class TimeSeries extends Calculator
|
|||
'startTime' => '-24 hours',
|
||||
];
|
||||
|
||||
public function __construct(Database $database, InfluxDatabase $influxDB, callable $errorHandler = null)
|
||||
public function __construct(string $region, Database $database, InfluxDatabase $influxDB, callable $errorHandler = null)
|
||||
{
|
||||
parent::__construct($region);
|
||||
$this->database = $database;
|
||||
$this->influxDB = $influxDB;
|
||||
$this->errorHandler = $errorHandler;
|
||||
|
@ -316,7 +317,7 @@ class TimeSeries extends Calculator
|
|||
'metric' => $metric,
|
||||
'value' => $value,
|
||||
'type' => $type,
|
||||
'region' => App::getEnv('_APP_REGION', 'default'),
|
||||
'region' => $this->region,
|
||||
]));
|
||||
} else {
|
||||
$this->database->updateDocument(
|
||||
|
|
Loading…
Reference in a new issue