2024-01-28 09:28:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Appwrite\Event;
|
|
|
|
|
|
|
|
|
|
use Utopia\Queue\Client;
|
|
|
|
|
use Utopia\Queue\Connection;
|
|
|
|
|
|
|
|
|
|
class UsageDump extends Event
|
|
|
|
|
{
|
|
|
|
|
protected array $stats;
|
|
|
|
|
|
|
|
|
|
public function __construct(protected Connection $connection)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($connection);
|
|
|
|
|
|
|
|
|
|
$this
|
|
|
|
|
->setQueue(Event::USAGE_DUMP_QUEUE_NAME)
|
|
|
|
|
->setClass(Event::USAGE_DUMP_CLASS_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add Stats.
|
|
|
|
|
*
|
|
|
|
|
* @param array $stats
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setStats(array $stats): self
|
|
|
|
|
{
|
|
|
|
|
$this->stats = $stats;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sends metrics to the usage worker.
|
|
|
|
|
*
|
|
|
|
|
* @return string|bool
|
|
|
|
|
*/
|
|
|
|
|
public function trigger(): string|bool
|
|
|
|
|
{
|
2024-11-08 20:55:53 +00:00
|
|
|
if ($this->paused) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-16 07:44:47 +00:00
|
|
|
$this->trimFields();
|
|
|
|
|
|
2024-01-28 09:28:59 +00:00
|
|
|
$client = new Client($this->queue, $this->connection);
|
|
|
|
|
|
|
|
|
|
return $client->enqueue([
|
|
|
|
|
'stats' => $this->stats,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|