update to use publisher

This commit is contained in:
Damodar Lohani
2025-02-05 09:53:29 +00:00
parent 3e778c0094
commit 68c3aa3078
5 changed files with 16 additions and 29 deletions
+3 -14
View File
@@ -2,13 +2,13 @@
namespace Appwrite\Event;
use Utopia\Queue\Connection;
use Utopia\Queue\Publisher;
class StatsResources extends Event
{
public function __construct(protected Connection $connection)
public function __construct(protected Publisher $publisher)
{
parent::__construct($connection);
parent::__construct($publisher);
$this
->setQueue(Event::STATS_RESOURCES_QUEUE_NAME)
@@ -26,15 +26,4 @@ class StatsResources extends Event
'project' => $this->project
];
}
/**
* Sends metrics to the usage worker.
*
* @return string|bool
*/
public function trigger(): string|bool
{
parent::trigger();
return true;
}
}
+8 -10
View File
@@ -3,17 +3,16 @@
namespace Appwrite\Event;
use Utopia\Database\Document;
use Utopia\Queue\Client;
use Utopia\Queue\Connection;
use Utopia\Queue\Publisher;
class StatsUsage extends Event
{
protected array $metrics = [];
protected array $reduce = [];
public function __construct(protected Connection $connection)
public function __construct(protected Publisher $publisher)
{
parent::__construct($connection);
parent::__construct($publisher);
$this
->setQueue(Event::STATS_USAGE_QUEUE_NAME)
@@ -51,17 +50,16 @@ class StatsUsage extends Event
}
/**
* Sends metrics to the usage worker.
* Prepare the payload for the event
*
* @return string|bool
* @return array
*/
public function trigger(): string|bool
protected function preparePayload(): array
{
$client = new Client($this->queue, $this->connection);
return $client->enqueue([
return [
'project' => $this->getProject(),
'reduce' => $this->reduce,
'metrics' => $this->metrics,
]);
];
}
}
+3 -3
View File
@@ -2,15 +2,15 @@
namespace Appwrite\Event;
use Utopia\Queue\Connection;
use Utopia\Queue\Publisher;
class StatsUsageDump extends Event
{
protected array $stats;
public function __construct(protected Connection $connection)
public function __construct(protected Publisher $publisher)
{
parent::__construct($connection);
parent::__construct($publisher);
$this
->setQueue(Event::STATS_USAGE_DUMP_QUEUE_NAME)
+1 -1
View File
@@ -58,7 +58,7 @@ class StatsUsage extends Action
}
//Todo Figure out way to preserve keys when the container is being recreated @shimonewman
$aggregationInterval = (int) System::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', '20');
$aggregationInterval = (int) System::getEnv('_APP_STATS_AGGREGATION_INTERVAL', '20');
$project = new Document($payload['project'] ?? []);
$projectId = $project->getInternalId();
foreach ($payload['reduce'] ?? [] as $document) {
+1 -1
View File
@@ -41,7 +41,7 @@ class Usage extends Action
$this->action($message, $project, $getProjectDB, $queueForUsageDump);
});
$this->aggregationInterval = (int) System::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', '20');
$this->aggregationInterval = (int) System::getEnv('_APP_STATS_AGGREGATION_INTERVAL', '20');
$this->lastTriggeredTime = time();
}